1

I've got a module set up to add discounts based on criteria defined in a category group (handle 'productPacks') -> category (which is a "pack").

Now, everything works great for one type of pack, and subsequent counts on that single pack, but as soon as there's other parts in the cart that correspond to other packs from the category group, no discounts are applied. I'm missing some logic in the code for how to distinguish and override a more expensive pack based on related products and which variants of that product are allowed to apply the larger discount based on said criteria.

I can't seem to get it to work so that each category is pushed as an adjustment into the adjustments array.

What am I missing? I'm checking cart contents against a category’s "related products" commerce product field (handle 'relatedProducts'), and then against which variants in those products are allowed (a commerce variants field with handle 'productVariants');

https://github.com/23d1/productcombos/blob/master/src/adjusters/OrderAdjuster.php

I'm simply checking the contents of the cart against the contents of a products field and a variants field in a set of categories in a specific category group. So no real relational stuff, simply comparing things to apply a discount amount that is a simple number field on the category it finds inside the specific category group (with the handle 'productPacks').

  • Are you trying to have a list of variants/product relations ON the category custom field? github.com/craftcms/commerce/issues/984 – Luke Holder Sep 3 '19 at 2:53
  • Yeah, essentially all the categories in the category group with the handle "productPacks", has fields like amount, related products and related variants. The title of the category then shows up as the description in the applied adjuster. It works perfectly fine for one single pack category, and if one adds more of the variants to the cart that correspond to the pack, it's multiplied by the lowest quantity of all those corresponding variants, however it doesn't work when adding variants that make up other packs. – Anders Sep 3 '19 at 2:55
  • Not sure if that's related to the issue you linked, as I'm just doing some hard-coded checks against a specific category. Could be entries or something else, if that makes sense? – Anders Sep 3 '19 at 3:36
  • Do you need thoseunset's? it might be removing the adjustment from the array? – Luke Holder Sep 3 '19 at 6:44
  • I get the same issue without. It’s essentially just resetting the variable for every item in the foreach loop, which is then eventually pushed into the $adjustments variable. Or at least that's the intent. So don’t need them I guess. Spaghetti code buildup. ;-) – Anders Sep 3 '19 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.