Hi,

I am starting to use Commerce Bundle module. A product bundle consists of multiple line items however it should count only as one product in cart (one bundle). Please see attached patch that solves this issue if Commerce Bundle module is enabled. Otherwise previous behaviour is unchanged.

Thank you.

CommentFileSizeAuthor
support_commerce_bundle.patch2.57 KBNeo13

Comments

Neo13 created an issue. See original summary.

subhojit777’s picture

Status: Needs review » Needs work

Looks good to me. Just some minor improvements I have suggested.

  1. +++ sites/all/modules/dc_ajax_add_cart/dc_ajax_add_cart.module	(date 1573907834946)
    @@ -301,9 +301,25 @@
    -        $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
    ...
    +        else {
    +          $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
    +        }
    

    Let the default $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types()); stay, and this else block will not be required.

  2. +++ sites/all/modules/dc_ajax_add_cart/dc_ajax_add_cart.module	(date 1573907834946)
    @@ -351,7 +367,22 @@
    -        $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
    ...
    +        else {
    +          $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
    +        }
    

    Let the default $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types()); and this else block will not be required.

Neo13’s picture

I added the else statement because I didn't want the commerce_line_items_quantity() function to run uselessly. That's a minor optimization but I will leave it up to your consideration.

subhojit777’s picture

hmm.. agree with you on that. However, I was unable to apply the patch. It gives error:

git apply support_commerce_bundle.patch
error: all/modules/dc_ajax_add_cart/dc_ajax_add_cart.module: No such file or directory

The path in the patch needs to be corrected.

tonytheferg’s picture

I confirm:

hmm.. agree with you on that. However, I was unable to apply the patch. It gives error:

git apply support_commerce_bundle.patch
error: all/modules/dc_ajax_add_cart/dc_ajax_add_cart.module: No such file or directory

The path in the patch needs to be corrected

I got the following trying to apply:

.$ patch -p1 < support_commerce_bundle.patch
(Stripping trailing CRs from patch; use --binary to disable.)
can't find file to patch at input line 8
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: sites/all/modules/dc_ajax_add_cart/dc_ajax_add_cart.module
|IDEA additional info:
|Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|<+>UTF-8
|===================================================================
|--- sites/all/modules/dc_ajax_add_cart/dc_ajax_add_cart.module (date 1572802154000)
|+++ sites/all/modules/dc_ajax_add_cart/dc_ajax_add_cart.module (date 1573907834946)
--------------------------
File to patch: dc_ajax_add_cart.module
patching file dc_ajax_add_cart.module
Hunk #1 succeeded at 294 (offset -7 lines).
Hunk #2 succeeded at 360 (offset -7 lines).

So i got the patch to apply to 7.x-2.11, but the functionality of adding bundles to cart did not change.