Bundles are challenging. Very challenging. Some rumaging around in the code exposes:
file: app/code/core/Mage/Bundle/Helper/Catalog/Product/Configuration.php
class: Mage_Bundle_Helper_Catalog_Product_Configuration
function: getBundleOptions()
public function getBundleOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item)
{
$options = array();
//...
foreach ($bundleSelections as $bundleSelection) {
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
if ($qty) {
$option['value'][] = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName())
. ' ' . Mage::helper('core')->currency(
$this->getSelectionFinalPrice($item, $bundleSelection)
);
}
}
//...
}
This is called via
file: app/code/core/Mage/Bundle/Block/Checkout/Cart/Item/Renderer.php
class: Mage_Bundle_Block_Checkout_Cart_Item_Renderer
function: getOptionList()
public function getOptionList()
{
return Mage::helper('bundle/catalog_product_configuration')->getOptions($this->getItem());
}
//AND via:
//Mage_Bundle_Block_Checkout_Cart_Item_Renderer getOptions(
//Mage_Bundle_Block_Checkout_Cart_Item_Renderer getOptionList()
//default.phtml : <?php if ($_options = $this->getOptionList()):?>
But it isn't obvious. I think $this
in default.phtml
is Mage_Bundle_Block_Checkout_Cart_Item_Renderer
due to:
//file: app/design/frontend/base/default/layout/bundle.xml
//Code:
//...
<checkout_cart_index>
<reference name="checkout.cart">
<action method="addItemRender"><type>bundle</type><block>bundle/checkout_cart_item_renderer</block><template>checkout/cart/item/default.phtml</template></action>
</reference>
//...
</checkout_cart_index>
//...
So, how to get what you want? You could write your own item renderer and use XML in local.xml to point to Magento to that. You could extend the class and write your own 'getBundleOptions()
' function. That would be the formal way. One shortcut is to copy the file
app/code/core/Mage/Bundle/Helper/Catalog/Product/Configuration.php
to
app/code/local/Mage/Bundle/Helper/Catalog/Product/Configuration.php
and edit that file, with the risk of future problems when you upgrade Magento because your local file will always be called, never the new version. Maybe that is okay as long as you and future developers are aware of it. I can tell you that file does change in 1.8.0 but at first glance the changes are superfluous.
Anyway, I often look at these things and say life is too short. Why not modify the .phtml file a little bit?
[At this point I have to ask about your note above that each option value ends with <br />
I think that is due to a custom theme which is but I don't know where your <br />
is coming from.]
Turning to the default.phtml file 'default.phtml
', we might just apply some string manipulation if the product type is bundle: (code not tested, just written here)
file: app/design/frontend/yourtheme/default/template/checkout/cart/item/default.phtml
code:
//...
//find this bit of code (it is at the end of a longer line)
//<?php echo $_formatedOptionValue['value'] ?>
//change it as you see fit, for example
<?php
if ($_item->getProduct()->getType()=='bundle'){
//manipulate the string:
$myOriginalOptionValue = $_formatedOptionValue['value'];
$myPreferredOptionValue = preg_replace("#^[0-9]+\sx\s#","",$myOriginalOptionValue);
echo $myPreferredOptionValue;
}else{
//carry on as before
echo $_formatedOptionValue['value'];
}
?>
//...
I hope it works out for you. Customising bundle display code is difficult because the blocks are deeply nested.
finally my config product has added to cart using magento api
$product = array(
'product_id' => 19, // config product id
'sku' => 'H001',
'qty' => '1',
'super_attribute' => array(
0 => array(
'key' => 92, //attribute id
'value' => 10 //value
),
1 => array(
'key' => 134,
'value' => 3
)
)
);
$client->shoppingCartProductAdd($session,$cartId, array($product));
Best Answer
As you can see in the documentation from your link above, the shoppingCartProductEntity array attribute "options" is an associativeArray in the form of
option_id => content
.I found a nice answer on stackoverflow "Setting Custom Options while adding a product to cart via SOAP in Magento" regarding this problem and the declaration as provided in the documentation does not seem correct.
The right way seems to be: