I have a few different attributes that can be configured for a product. When that product is added to the cart, theoretically the cart would check those attributes, and if they don't match, it creates a new line item.
Currently, it is just increasing the quantity, basically adding the item using whatever attributes were used the first time someone added the product to the cart.
These attributes are created via modules, not within the custom options of the product.
I've tried all of the different combinations of suggestions throughout this site and others, and nothing seems to fix the problem.
Setting up the columns worked just fine. They were added to both tables:
$setup = new Mage_Sales_Model_Mysql4_Setup('core_setup');
$setup->startSetup();
$setup->addAttribute('quote_item', 'exclude_protein', array('type' => 'varchar', 'visible' => true, 'required' => false));
$setup->addAttribute('order_item', 'exclude_protein', array('type' => 'varchar', 'visible' => true, 'required' => false));
$setup->addAttribute('quote_item', 'sub_protein', array('type' => 'varchar', 'visible' => true, 'required' => false));
$setup->addAttribute('order_item', 'sub_protein', array('type' => 'varchar', 'visible' => true, 'required' => false));
$setup->addAttribute('quote_item', 'exclude_sides', array('type' => 'varchar', 'visible' => true, 'required' => false));
$setup->addAttribute('order_item', 'exclude_sides', array('type' => 'varchar', 'visible' => true, 'required' => false));
$setup->addAttribute('quote_item', 'sub_sides', array('type' => 'varchar', 'visible' => true, 'required' => false));
$setup->addAttribute('order_item', 'sub_sides', array('type' => 'varchar', 'visible' => true, 'required' => false));
$this->endSetup();
The fieldsets and sales groups in the config file were added because that was the fix that was suggested the most. My cart acts the same whether that section is there or not.
<global>
<fieldsets>
<sales_convert_quote_item>
<exclude_protein>
<to_order_item>*</to_order_item>
</exclude_protein>
<sub_protein>
<to_order_item>*</to_order_item>
</sub_protein>
<exclude_sides>
<to_order_item>*</to_order_item>
</exclude_sides>
<sub_sides>
<to_order_item>*</to_order_item>
</sub_sides>
</sales_convert_quote_item>
</fieldsets>
<sales>
<quote>
<item>
<product_attributes>
<exclude_protein />
<sub_protein />
<exclude_sides />
<sub_sides />
</product_attributes>
</item>
</quote>
</sales>
<models>
<ecb_modifymeal>
<class>ECB_ModifyMeal_Model</class>
</ecb_modifymeal>
<sales>
<rewrite>
<quote_item>ECB_ModifyMeal_Model_Sales_Quote_Item</quote_item>
</rewrite>
</sales>
</models>
<events>
<sales_quote_add_item>
<observers>
<ecb_modifymeal_observer>
<class>ECB_ModifyMeal_Model_Observer</class>
<method>modifyPrice</method>
</ecb_modifymeal_observer>
</observers>
</sales_quote_add_item>
</events>
<resources>
<ecb_modifymeal_setup>
<setup>
<module>ECB_ModifyMeal</module>
<class>Mage_Catalog_Model_Resource_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</ecb_modifymeal_setup>
</resources>
</global>
In my observer, I am adjusting the price. That logic is removed since it is working just fine. It is represented by the "..." and is where I am defining the $increase_amount
variable.
class ECB_ModifyMeal_Model_Observer {
public function modifyPrice(Varien_Event_Observer $observer) {
$item = $observer->getQuoteItem();
$post_vals = Mage::app()->getRequest()->getParams();
...
$final_price = $item->getProduct()->getPrice() + $increase_amount;
$item->setData('exclude_protein', rtrim($exclude_protein, ','));
$item->setData('sub_protein', rtrim($sub_protein, ','));
$item->setData('exclude_sides', rtrim($exclude_sides, ','));
$item->setData('sub_sides', rtrim($sub_sides, ','));
$item->setCustomPrice($final_price);
$item->setOriginalCustomPrice($final_price);
$item->getProduct()->setIsSuperMode(true);
}
}
This is what I've come up with so far for the ECB > ModifyMeal > Model > Sales > Quote > Item.php file. It adds the first item, and doesn't add any other of that product, even if it's the same:
class ECB_ModifyMeal_Model_Sales_Quote_Item
extends Mage_Sales_Model_Quote_Item
{
public function representProduct($product) {
$parentResult = parent::representProduct($product);
if ($parentResult === false) {
return $parentResult;
}
$itemProduct = $this->getQuoteItem();
$productExP = $product->getData('exclude_protein');
$productSubP = $product->getData('sub_protein');
$productExS = $product->getData('exclude_sides');
$productSubS = $product->getData('sub_sides');
$itemExP = $itemProduct->getData('exclude_protein');
$itemSubP = $itemProduct->getData('sub_protein');
$itemExS = $itemProduct->getData('exclude_sides');
$itemSubS = $itemProduct->getData('sub_sides');
if($productExP == $itemExP && $productSubP == $itemSubP && $productExS == $itemExS && $productSubS == $itemSubS){
return true; //same product
} else {
return false; //different product
}
}
}