First off, this is an awesome module.

I have been working on this module to get it working for a client that needs it. Unfortunately, their products are best displayed with Attributes that modify the price and show how the customer wants it delivered (their products are educational courses). But only some attribute options should be discounted. When trying to `Filter by SKU`, only the base product's SKU would show up and none of the SKUs set by attribute adjustments; this was a bit troubling. So, in turn, I cracked open the module and admin.inc files and proceed to make it work for my client. Then afterwards, I sat down and went through the all relevant code and very finely corrected it to work as it should with attribute adjustments.

The code I changed has been over-commented and usually looks like...

// BEGIN MARCUS EDIT (<DATE>)
[code ...]
// END MARCUS EDIT

I wrote this before the 2010/08/24 dev update and it would be really easy if I didn't have to manually change any future updates, so if you (maintainers) could review it and possible implement it (or something just as effective) in the next update it would be much appreciated.

Comments

nerdacus’s picture

Category: feature » bug
Priority: Normal » Major
Status: Needs review » Active

*bump*

I changed category, priority and status because I feel this is a major bug, since it is supposed to 'Filter by SKU', but what is the point if it does not acknowledge the SKUs created by attibutes (an optional core module).

Poieo’s picture

I've test these changes on the latest release and it works as expected.

This is a much needed feature. Unfortunately, it will never get included unless someone provides a patch against the latest release...

schackattack’s picture

@Poieo: how did you manage to do that --> test it against the latest release?

Poieo’s picture

StatusFileSize
new61.32 KB

@schackattack - Basically, I went through the attachment marcus provided line by line and moved his code into the latest release of the module.

I'm attaching the version of the module I'm using which is the 6.x-2.0 release with marcus's changes. If someone can role a patch, maybe we can get it committed.

schackattack’s picture

Thanks a lot! Works like a charm. This really should be patched and submitted. I think it's the only available option right now to offer discounts based on alternative skus, since the uc discount framework module doesn't work properly with the newest release of uc. Unfortunately I haven't learned to patch properly yet. :-)

tanjerine’s picture

This worked. Thank you. I did the same thing as #4 ... manually applied the patch.

msielski’s picture

Looks like 2.1 released on March 29th without this patch. Has anyone manually applied these changes to 2.1 yet? I am going to attempt to construct a patch against 2.1.

jerry’s picture

Subscribing.

msielski’s picture

2.1 introduced some new code that I did not have time to get familiar with, but needs similar patching done to it.

I ended up using 6.x-2.0 with the patch in comment #4 since I don't need the new features which 2.1 adds. This works really well and I'd love to see this become part of the module.

jrust’s picture

Status: Active » Needs work

If someone can roll this is a patch I'd be happy to apply it.

FranCarstens’s picture

I notice this is not in the latest dev. What's the latest on this?

jrust’s picture

Still awaiting an actual patch.

elc’s picture

Title: Discounts filtered by SKU, attribute adjustments fix » [patch] Discounts filtered by SKU, attribute adjustments fix. (Plus a few extras)
Status: Needs work » Needs review
StatusFileSize
new27.37 KB

o.O

So how many people manually added the changes and then didn't submit the results back?

Here's the patch, relative to the current HEAD, which at present seems to be the 6.x-2.4 version. I didn't get an notification of a new version and I'm thinking it's because the .info files had "6.x-2.x-dev" or "6.x-2.0" version left overs in them commited to the repository. This patch removes them too.

For those how don't know how to patch .. this is how it's done in a very simple way. There are more complicated way to go.

git clone --branch 6.x-2.x http://git.drupal.org/project/uc_discounts_alt.git
cd uc_discounts_alt
vi uc_discounts/uc_discounts.admin.inc
vi uc_discounts/uc_discounts.module
git commit -a -m "Issue #900010 by ELC: Discounts filtered by SKU, attribute adjustments fix."
# and here's the the one line that creates the patch
git format-patch HEAD~1

Apply to git HEAD fa013d5579f82d63797379c26b4340f540aacb59 with

git am < 900010-uc_discounts_alt-filtered-by-sku.patch

There were a few things wrong with the code as supplied, and I had to change some parts because they no longer matched the logic at all. There was even the rather major bug that it required uc_attributes to be installed and would throw errors without it.

This patch also fixes a bug in the saving of SKU qualification filters.

Full patch log:
Issue #900010 by ELC: Discounts filtered by SKU, attribute adjustments fix.

Adjust admin.inc to pull all SKUs out.
Make admin.inc changes contingent on uc_attribute being installed.
Add remainder of workings to get SKU adjustments to work.
Make .module file check for uc_attribute.

Some semi-related, and completely unrelated things changed in this patch too.
Fix typo in uc_discounts_form_submit that prevented SKUs from required products being saved properly.
Also swapped a few "" to ''. Needs wholesale change throughout the code.
Removed erroneous version and other related variables from .info files
Remove defunct .cvsignore file.
Removed all the CVS Id tags from files.

elc’s picture

Sorry, add this one on too, perhaps as an amend to the last one :P I left a marker in the code so I could search back to it quickly and see that the correct module was being loaded.

elc’s picture

*sheepish grin*

Found some more debugging code I added in that needs to be removed with this additional, additional patch. This one is actually sequential after #1314744: [patch] Use of more than one coupon of same discount for fixed price off.

jastylr’s picture

Just wondering if this is something that will make it into an official release any time soon. I tried to run the patch but as a noobie when it comes to doing that, I don't believe it went as planned. I used Netbeans to do it and got a message saying that it was partially patched.

Going into the admin page for the discounts, I saw that I can now select an alternate SKU to apply the discounts to based on attribute adjustments but it didn't appear to actually work. Perhaps I'm missing some other piece of the puzzle?

I have a product with several attributes, one of which is an age field. I want to provide a discount of $5 off each item where the age is older than 12 years and cart quantity is 10 or greater. I have setup an alternate SKU for the 12 and under age attribute leaving all other age attributes set to the default product SKU.

In the discounts admin page, I setup the discount to qualify with a minimum quantity of 10 with a fixed amount off of $5 and filter by the default SKU only. The quantity of 10 or more discount works fine but does not take into account the SKU. It simply applies the discount when 10 or more of the product are added to the cart.

To test, I added a quantity of 9 products where the age attribute was set to 18 years old. This attribute would get the default SKU as set in the "Adjustments" section of the product. I then added a single additional product to the cart where the age attribute was set to 12 and under. This attribute uses a different SKU than the one setup to apply for the discount.

When added to the cart, the discount still gets applied as there are 10 items in the cart but it should not since one of the products has a different SKU based on the age attribute.

Am I doing this correctly?

Thanks in advance!

jastylr’s picture

Went through and applied the patch manually and everything is good now. Works like I would expect.

It would still be nice to see this in an official release.

elc’s picture

Did you also include the patch from #1314744: [patch] Use of more than one coupon of same discount for fixed price off prior to attempting to add this patch? I needed both of them so the patches are intertwined.

I'm using this patched version in a production site so perhaps I should approach the module maintainer to see if could help. I've also got a companion module that adds some extra useful stuff which would be better to be included.

This patch has been sitting around for ... a while.

occucopy’s picture

Category: bug » feature

Wow, this is a much-needed bug in the core. Is there any way to get a roll/port of this for the D7 port here?: http://drupal.org/node/1035264#comment-5315538

stewart.adam’s picture

This patch works well, however there are two problems:

  1. Both the product qualifying and application filters MUST be set to "Filter by SKUs" or else the discounts module will not find any qualifying products and the discount application will fail. This is due to $sku_filter_flag being used, so $discount->filter_type is checked (the application filter) but not the qualification filter type
  2. This seems to be broken without the patch as well so this should be resolved in a separate issue, but a warning to users: ALL of the generic selections such as "No specific product" or "" are completely broken due to the way uc_discounts handles product searches. It looks in the {uc_discount_skus} for matching product SKUs, but by convention will save no skus to this table to indicate an "all" selection. It becomes difficult then to determine the meaning of an empty query; no matches, or no entries (meaning match all?)

tl;dr: Always match using "Filter by SKU" and just select all products in there if necessary.

stewart.adam’s picture

Furthermore, this patch seems to move the call of this line:

$required_product_ids = get_product_ids_for_discount_object($discount, DISCOUNT_FILTER_GROUPING_QUALIFICATION);

into a conditional block that is only executed when filter by SKU is set. The result is that determining required product IDs is broken for all non-SKU based filters.

hockey2112’s picture

How would I go about applying this patch to 6.x-2.4? Is it compatible with that version?