3

I have built a model that can add some custom design info (link to pdg, design type, document id, upload location) to the quote items. The design screen is opened in a popup, and saves the design values to the session

In the sales_quote_add_item observer I look at which design is in the session (weather that is the best idea or not is not the point)

So far so good

The problem I am facing is the following one:

On reordering 2 configurable products (same config options, same "child" sku") but with different designs only one quote-line with qty = 2 is added with the design options of the last product from the original order

This should have been 2 quote-lines with 1 qty = 2 with each their own design

I have tried debugging the problem down from

Mage_Checkout_Model_Cart::addOrderItem

Where I now force to add a different design method per item

$info->setDesignMethod((string)$orderItem->getDesignMethod());

To

Mage_Checkout_Model_Cart::addProduct

where var_dump($request); gives 2 different design_method's for 2 products

object(Varien_Object)[1470]
  protected '_data' => 
    array (size=10)
      'uenc' => string 'aHR0cDovL2R2Yy5kZXYubWVkaWFjdGhxLm5sL2JlYWNodmxhZy1zcGxhc2g,' (length=60)
      'product' => string '3119' (length=4)
      'form_key' => string 'ToaYzvESXcg2k56k' (length=16)
      'related_product' => string '' (length=0)
      'super_attribute' => 
        array (size=6)
          187 => string '1143' (length=4)
          254 => string '1397' (length=4)
          188 => string '121' (length=3)
          186 => string '390' (length=3)
          192 => string '384' (length=3)
          193 => string '389' (length=3)
      'productiontime_sku' => string 'production-24h' (length=14)
      'idSimple' => string '73' (length=2)
      'designoptions' => string 'true' (length=4)
      'qty' => string '1.0000' (length=6)
      'design_method' => string 'online_design' (length=13)
  protected '_hasDataChanges' => boolean true
  protected '_origData' => null
  protected '_idFieldName' => null
  protected '_isDeleted' => boolean false
  protected '_oldFieldsMap' => 
    array (size=0)
      empty
  protected '_syncFieldsMap' => 
    array (size=0)
      empty

object(Varien_Object)[1808]
  protected '_data' => 
    array (size=10)
      'uenc' => string 'aHR0cDovL2R2Yy5kZXYubWVkaWFjdGhxLm5sL2JlYWNodmxhZy1zcGxhc2g,' (length=60)
      'product' => string '3119' (length=4)
      'form_key' => string 'ToaYzvESXcg2k56k' (length=16)
      'related_product' => string '' (length=0)
      'super_attribute' => 
        array (size=6)
          187 => string '1143' (length=4)
          254 => string '1397' (length=4)
          188 => string '121' (length=3)
          186 => string '390' (length=3)
          192 => string '384' (length=3)
          193 => string '389' (length=3)
      'productiontime_sku' => string 'production-24h' (length=14)
      'idSimple' => string '73' (length=2)
      'designoptions' => string 'true' (length=4)
      'qty' => string '1.0000' (length=6)
      'design_method' => string 'offline_design' (length=12)
  protected '_hasDataChanges' => boolean true
  protected '_origData' => null
  protected '_idFieldName' => null
  protected '_isDeleted' => boolean false
  protected '_oldFieldsMap' => 
    array (size=0)
      empty
  protected '_syncFieldsMap' => 
    array (size=0)
      empty

To

Mage_Sales_Model_Quote::addProductAdvanced

where Mage_Sales_Model_Quote::_prepareProduct is called

Before returning $product the buy requests shows different design options for the products

$optionstest = $product->getCustomOptions();
var_dump($optionstest['info_buyRequest']->getValue());

gives:

string 'a:10:{s:4:"uenc";s:60:"aHR0cDovL2R2Yy5kZXYubWVkaWFjdGhxLm5sL2JlYWNodmxhZy1zcGxhc2g,";s:7:"product";s:4:"3119";s:8:"form_key";s:16:"ToaYzvESXcg2k56k";s:15:"related_product";s:0:"";s:15:"super_attribute";a:6:{i:187;s:4:"1143";i:254;s:4:"1397";i:188;s:3:"121";i:186;s:3:"390";i:192;s:3:"384";i:193;s:3:"389";}s:18:"productiontime_sku";s:14:"production-24h";s:8:"idSimple";s:2:"73";s:13:"designoptions";s:4:"true";s:3:"qty";s:6:"1.0000";s:13:"design_method";s:13:"online_design";}' (length=476)
string 'a:10:{s:4:"uenc";s:60:"aHR0cDovL2R2Yy5kZXYubWVkaWFjdGhxLm5sL2JlYWNodmxhZy1zcGxhc2g,";s:7:"product";s:4:"3119";s:8:"form_key";s:16:"ToaYzvESXcg2k56k";s:15:"related_product";s:0:"";s:15:"super_attribute";a:6:{i:187;s:4:"1143";i:254;s:4:"1397";i:188;s:3:"121";i:186;s:3:"390";i:192;s:3:"384";i:193;s:3:"389";}s:18:"productiontime_sku";s:14:"production-24h";s:8:"idSimple";s:2:"73";s:13:"designoptions";s:4:"true";s:3:"qty";s:6:"1.0000";s:13:"design_method";s:12:"offline_design";}' (length=475)

These options are also available in

Mage_Sales_Model_Quote::_addCatalogProduct

But for some reason Magento adds 2 of the same products with 1 design

I do not have these problems if I order 2 configurable products with different options (another "child" sku)

My guess is that my configurable just isn't unique enough

I just need to figure out how to make it unique enough for magento to make it 2 different quote items with qty = 1

My guess was that by modifying the "info_buyRequest" this could be done

Question:

How do I make configurable products unique enough to add them as separate cart lines on reordering?

2 Answers 2

1

The logic to determine if a item is to be added to the cart as a line item is here: Mage_Sales_Model_Quote_Item::representProduct

Yes, you are correct in the fact that if you make the info_buyRequest unique, then the representProduct routine should return a false (thus separate line items)

This can be seen by this code in the routine:

$itemOptions = $this->getOptionsByCode();
$productOptions = $product->getCustomOptions();

if (!$this->compareOptions($itemOptions, $productOptions)) {
    return false;
}
if (!$this->compareOptions($productOptions, $itemOptions)) {
    return false;
}

This should give you a place to debug, and figure out why your info_buyrequest are not triggering the uniqueness.

If I can also suggest to get a debugger going, and step through the code, rather than relying on echo debugging. It will make your life a lot easier :)

0

You can add a hidden option like this

$quoteItem->addOption(new Varien_Object(array(
    'product' => $product,
    'code' => 'design_method',
    'value' => $designMethod
    )));

These options are, unlike the buyRequest option, used for comparison when Magento determines, which items should be merged.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.