Skip to content

Instantly share code, notes, and snippets.

@mcjwsk
Last active July 10, 2017 10:33
Show Gist options
  • Save mcjwsk/753cc20bff540d7fe24f56b02a48facc to your computer and use it in GitHub Desktop.
Save mcjwsk/753cc20bff540d7fe24f56b02a48facc to your computer and use it in GitHub Desktop.
<?php
require_once 'app/Mage.php';
Mage::app();
$quote = Mage::getModel('sales/quote')->load(197643);
/** @var Mage_Sales_Model_Quote_Item $item */
foreach ($quote->getAllVisibleItems() as $item) {
$option = $item->getOptionByCode('additional_options');
$additonalOptions = array();
if ($option) {
$additonalOptions = unserialize($option->getValue());
foreach ($additonalOptions as $key => $additonalOption) {
if ('my_code' === $additonalOption['code']) {
unset($additonalOptions[$key]);
}
}
}
$additonalOptions[] = array(
'code' => 'my_code',
'label' => 'This text is displayed through additional options',
'value' => 'ID is ' . $item->getProductId() . ' and SKU is ' . $item->getSku()
);
// @see Mage_Catalog_Helper_Product_Configuration
// @see Mage_Catalog_Model_Product_Option_Type_File
$item->addOption(new Varien_Object(array(
'product' => $item->getProduct(),
'code' => 'additional_options',
'value' => serialize($additonalOptions),
)));
}
$quote->collectTotals();
$quote->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment