Compatibility with module commerce_variation_cart_form

Created on 21 July 2023, over 1 year ago
Updated 6 September 2023, over 1 year ago

Problem/Motivation

The version 1.1 is not compatible with commerce_variation_cart_form.

Steps to reproduce

Try to add a product variation to cart. We get this error :

TypeError : Argument 1 passed to commerce_stock_enforcement_get_context() must implement interface Drupal\commerce\PurchasableEntityInterface, null given, called in /var/www/html/modules/contrib/commerce_stock/modules/enforcement/commerce_stock_enforcement.module on line 144 dans commerce_stock_enforcement_get_context() (/var/www/html/modules/contrib/commerce_stock/modules/enforcement/commerce_stock_enforcement.module ligne 290)

Proposed resolution

diff --git a/modules/enforcement/commerce_stock_enforcement.module b/modules/enforcement/commerce_stock_enforcement.module
index 7ffabde..79f39a6 100644
--- a/modules/enforcement/commerce_stock_enforcement.module
+++ b/modules/enforcement/commerce_stock_enforcement.module
@@ -28,8 +28,8 @@ function commerce_stock_enforcement_form_alter(
 ) {

   // Add to cart forms.
-  $build_info = $form_state->getBuildInfo();
-  if (!empty($build_info['callback_object']) && $build_info['callback_object'] instanceof AddToCartFormInterface) {
+  if (strpos($form_id, "commerce_order_item_add_to_cart_form") !== FALSE
+    || strpos($form_id, "commerce_order_item_dc_ajax_add_cart_form") !== FALSE) {
     // Get the product variation.
     $selected_variation_id = $form_state->get('selected_variation');
     if (!empty($selected_variation_id)) {

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • 🇮🇳India mohd sahzad

    I have fixed this issue TypeError : Argument 1 passed to commerce_stock_enforcement_get_context() must implement interface Drupal\commerce\PurchasableEntityInterface, null given,called in /var/www/html/modules/contrib/commerce_stock/modules/enforcement/commerce_stock_enforcement.module on line 144 dans commerce_stock_enforcement_get_context() (/var/www/html/modules/contrib/commerce_stock/modules/enforcement/commerce_stock_enforcement.module ligne 290)

Production build 0.71.5 2024