Last active
April 27, 2019 02:36
-
-
Save AndresInSpace/3a7c4ca83abd043ec68b07cdbca0af75 to your computer and use it in GitHub Desktop.
Magento 1 Add Product To Cart w Custom Options [CartController or Observer Methods]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$custom_option1 = array('label'=>'Custom1','value'=>$value1); | |
$custom_option2 = array('label'=>'Custom2','value'=>$value2); | |
$product->addCustomOption('additional_options', serialize(array($custom_option1,$custom_option2))); | |
$product->setHasOptions(true); | |
$cart->addProduct($product, $params); | |
$cart->save(); | |
//USE 'additional_options' if you need the CustomOption to show up on checkout/cart, as $item->getCustomOptions() only looks at 'additional_options' and 'option_ids' | |
$item->getOptionByCode('option_ids'); | |
$item->getOptionByCode('additional_options'); | |
//in app/code/core/Mage/Catalog/Helper/Product/Configuration.php | |
//So we can use instead: | |
$product->addCustomOption('real_custom_option_group',serialize(array($custom_option1,$custom_option2))); | |
//and to retrieve: | |
$optiongroup = $item->getOptionByCode('real_custom_option_group'); | |
$options = unserialize($optiongroup->getValue()); | |
foreach($options as $option){ | |
//do things with the $option@array('label'=>'Custom1','value'=>$value1) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment