Magento Cart: show selected option value information form Custom Options selection

I wanted to get a custom "front_image_path" from the customoptions that I have implemented with MageWorx. This way I can have a shirt with multiple image options to select from for color and that will show in cart. So this code goes in the "app/design/frontend/default/default/template/checkout/cart/item/default.phtml" to modify the frontimage.
  
    // this is for non-customizable products
    $_options = $_product->getOptions();
    // if option enabled = no && hasOptions = 0
    if (!$_options) $optionsArr = $this->getProduct()->getProductOptionsCollection();

    /** @var MageWorx_CustomOptions_Helper_Data $helper */
    $helper = Mage::helper('customoptions');
    foreach ($_options as $_option) {
        /** @var MageWorx_CustomOptions_Model_Catalog_Product_Option $_option */
        if(strtolower($_option->getTitle())=='color'){
            // this option id
            $option_id = $_option->getId();
            // cart item option info
            $item_option = $_item->getOptionByCode('option_' . $option_id);

            foreach ($_option->getValues() as $_value) {
                /** @var Mage_Catalog_Model_Product_Option_Value $_value */
                //
                $value_type = $_value->getOptionTypeId();
                if($item_option && $value_type == $item_option['value']){
                    $frontImgArr = $helper->getColorImgHtml($_value->getFrontImagePath(), $option_id, $value_type,true,true,'front');
                    $frontimage = $frontImgArr['url'];
                }
            }
        }
    }
    if(empty($frontimage)){
        $frontimage = $this->getProductThumbnail();
    }

Popular Posts