Ali Nasrullah
Ali Nasrullah

Reputation: 131

How to send Product Selected Custom Option Sku Field to cart page in Magento

I am working in a scenario I want to send Product selected Custom Option SKU in cart page have founded the array which is sent to cart in case of custom options.

Here is a Function called getProductOptions() in which Product Option Array is created and sent to cart. At this point, I want to send selected Custom Option SKU field to cart.

I have the following code:

public function getProductOptions()
{
    $options = array();
    if ($optionIds = $this->getItem()->getOptionByCode('option_ids')) {
        $options = array();
        foreach (explode(',', $optionIds->getValue()) as $optionId) {
            if ($option = $this->getProduct()->getOptionById($optionId)) {

//echo $optionId;   
                echo "hhhhhhhhhhhhh";
//print_r( $option->getId());
//echo Mage::getModel('catalog/product')->getOptionSku($option);
//die();
//print_r( $option->getOptionSku());
//echo Mage_Catalog_Model_Product_Option_Type_Select::getOptionSku());

                $quoteItemOption = $this->getItem()->getOptionByCode('option_' . $option->getId());
//echo $option->getQuoteItemOption($quoteItemOption);
                $group = $option->groupFactory($option->getType())
                    ->setOption($option)
                    ->setQuoteItemOption($quoteItemOption);
                $options[] = array(
                    'label' => $option->getTitle(),
                    'value' => $group->getFormattedOptionValue($quoteItemOption->getValue()),
                    'print_value' => $group->getPrintableOptionValue($quoteItemOption->getValue()),
                    'option_id' => $option->getId(),
                    'option_type' => $option->getType(),
                    'custom_view' => $group->isCustomizedView(),
                    'option_sku'=>//What should i call here to send Selected option SKU to this Array
                );
            }
        }    
        if ($addOptions = $this->getItem()->getOptionByCode('additional_options')) {
            $options = array_merge($options, unserialize($addOptions->getValue()));
        }
    }
    return $options;
}

Upvotes: 0

Views: 3751

Answers (2)

clockworkgeek
clockworkgeek

Reputation: 37700

It looks like the bit you're missing is

'option_sku' => $this->getItem()->getSku()

Upvotes: 2

Joe Mastey
Joe Mastey

Reputation: 27099

Don't modify the block itself, just change the rendered template to add a for this field. Grab the data from the $_item variable, and echo it out to the user. That should require no modifications of the block.

Upvotes: 0

Related Questions