Closed proseLA closed 10 months ago
It seems wrong to me as well. I'm envisioning (especially in this season) a "Black Friday" category of products that is some percent-off.
Running with the current master repository, I've set that category restriction:
Placing Hewlett Packard LaserJet 1100Xi Linked
in the cart, navigating to the checkout_payment
page and entering the associated coupon-code, I'm seeing that the coupon's deduction is applied.
What's different between my setup and yours?
i believe your coupon is setup incorrectly. try adding anything else to your cart. does the coupon also apply to something else not in that category?
in my experience, the coupon needs to be setup like so to restrict to a category:
you can see where it validates the category here:
the code only checks the categories that come back from the zen_get_product_path
method.
my solution would be to change that section of code and add the following method:
function validate_for_category(int $product_id, int $coupon_id)
{
global $db;
$productCatPath = zen_get_product_path($product_id) . getLinkedCategories($product_id);
$catPathArray = array_unique(array_reverse(explode('_', $productCatPath)));
...
function getLinkedCategories(int $productId): string
{
global $db;
$sql = 'SELECT categories_id FROM ' . TABLE_PRODUCTS_TO_CATEGORIES . "
WHERE products_id = $productId";
$result = $db->Execute($sql);
$catString = '';
if ($result->EOF) {
return $catString;
}
foreach ($result as $value) {
$catString .= '_' . $value['categories_id'];
}
return $catString;
}
i believe your coupon is setup incorrectly. try adding anything else to your cart. does the coupon also apply to something else not in that category?
With that coupon setup, the coupon only applies to a product in the Big Linked
category:
Although I do see that adding (per the docs reference) that 'start by excluding all categories' restriction causes the coupon to no longer be applied to the order.
i am having trouble reproducing, but here is a thought. for the coupon that you have set up, add another valid category. my theory is that the linked product will now not be valid. the code looks for only a single restriction and applies the logic differently with 1 restriction as opposed to more than 1 restriction.
i have confirmed this theory.
in the test data, product
Hewlett Packard LaserJet 1100Xi Linked
, has a master category ofPrinters
, but is also in the category ofBig Linked
(at least it is in my test data...).if one were to set up a coupon that was ONLY valid for
Big Linked
products, this product would not be valid.is this behavior intended/expected?
it seems wrong to me.