Example:
Buy any 3 "T-shirts", Get any 3 "Shorts" at 50% off.
or
Buy any 3 "Red" T-shirts, Get any 3 "Red" T-shirts at 50% off, where Red is a taxonomy term.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

junetellain626’s picture

Title: Buy X product (type), Get Y product (type) » Buy X product (of type or term), Get Y product (of type or term)
Issue summary: View changes
rszrama’s picture

Project: Commerce Discount Extra » Commerce Discount
Version: 7.x-1.0-alpha2 » 7.x-1.x-dev
Status: Active » Postponed

This is basically an additional BOGO condition that would need to be added after Commerce Discount Extra is merged in.

michfuer’s picture

Status: Postponed » Needs review
FileSize
31.48 KB

This is a patch for commerce_discount_extra. It creates two new offer types based on product categories. It's a bit heavy due to some refactoring of the install code to make offer types and their fields more manageable.

The term select list (product categories) is not grouped by vocabulary atm due to this issue https://www.drupal.org/node/1180992

Status: Needs review » Needs work

The last submitted patch, 3: commerce_discount_extra-category_offer_types-2159655-3.patch, failed testing.

joelpittet’s picture

Project: Commerce Discount » Commerce Discount Extra
joelpittet’s picture

Status: Needs work » Needs review
rszrama’s picture

Ok, the refactoring of the .install file definitely should've come in a separate patch. I think it's good to go, but I did relegate the consideration of the uninstall hook to a separate issue to try to minimize the impact of this patch: #2663820: Uninstall Commerce Discount Extra field instances on module uninstallation

I did some light refactoring of the refactoring (function names, comments) and will review the new offer type itself ASAP. I also really can't imagine this working without some sort of hierarchy apparent in the term list, so we may need to retool that allowed values callback further. There are bound to be any number of terms that have the same name at different depths and as different subcategories in any decently sized product catalog.

rszrama’s picture

Status: Needs review » Needs work
FileSize
32.05 KB

Work in progress patch attached. Also, marking needs work as I know commerce_discount_extra_product_terms() needs to be optimized a little and have a query tag attached to its EFQ, and the action name and callback need to be changed to include "per_quantity" if possible. commerce_discount_extra_category is too vague.

rszrama’s picture

Status: Needs work » Fixed
FileSize
34.68 KB

Ok, went through and confirmed the main feature itself worked (it does : ). I ended up changing some names of the offer types / functions / action so it was uniform with what we already had, but I made two other significant changes:

  1. The allowed values callback may not be able to use option groups, but it could still use the term depth indicators as seen in taxonomy_allowed_values(). I copied the code for now with notes about how we'll update it when the patch michfuer linked above lands.
  2. I added a static cache to the function that generates the allowed values list and to the function that determines term IDs associated with a given product. No need to run those queries multiple times per page load.
  3. I added a tag to the EFQ used to find nodes referencing the given product so the query could easily be altered by third parties needing to disable access control on the query.

Attached and committed.

  • rszrama committed 3a3d123 on 7.x-1.x authored by michfuer
    Issue #2159655 by rszrama, michfuer: Buy X product (of type or term),...
lelivero’s picture

Hi rszrama, thanks for the work.

It's working when I fill in all the fields, but when I leave the field "On up to #" empty I get a general error. When I go back to the discounts overview my previously stored discount is even deleted.
I tested it on the "Per-quantity category discount ($ off)" and "Per-quantity category discount (% off)" options.
(Commerce Kickstart 7.x-2.33, Commerce discount v7.x-1.0-alpha7)

joelpittet’s picture

@lelivero can you share the error message, it may be in your watchdog or system logs.

lelivero’s picture

Yes, this is what I found in the log messages for every time I tried it:

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'commerce_offer_limit_value' at row 1: INSERT INTO {field_data_commerce_offer_limit} (entity_type, entity_id, revision_id, bundle, delta, language, commerce_offer_limit_value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => commerce_discount_offer [:db_insert_placeholder_1] => 23 [:db_insert_placeholder_2] => 23 [:db_insert_placeholder_3] => per_quantity_percentage [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => ) in field_sql_storage_field_storage_write() (line 514 of W:\sites\THseeds\wwwroot\modules\field\modules\field_sql_storage\field_sql_storage.module).

rszrama’s picture

Status: Fixed » Needs work

I can reproduce this. Let me look into it - not sure why the field and its form validation would differ off the top of my head.