Question

I am working with options, to add some additional info like image. and i saved this data to my own table with option_type_id and option_id. now on frontend i would like to join my own table data to default options. so these options come with image info.

$_option->getValues() 

this function returns option data, now i have to reach at the implementation of this function where it generate the query so i could add join to retrieve my own data with.

thanks

Was it helpful?

Solution 2

Here is what i got success from.

i overridden the resource collection of product

 class MYC_COPSwatch_Model_Resource_Product_Option_Collection extends Mage_Catalog_Model_Resource_Product_Option_Collection{        

     public function addValuesToResult($storeId = null)
{
    if ($storeId === null) {
        $storeId = Mage::app()->getStore()->getId();
    }
    $optionIds = array();
    foreach ($this as $option) {
        $optionIds[] = $option->getId();
    }
    if (!empty($optionIds)) {
        /** @var $values Mage_Catalog_Model_Option_Value_Collection */
        $values = Mage::getModel('catalog/product_option_value')
            ->getCollection()                
            ->addTitleToResult($storeId)
            ->addPriceToResult($storeId)                

            ->addSwatchToResult($storeId)   //USED Join in this function             

            ->setOrder('sort_order', self::SORT_ORDER_ASC)
            ->setOrder('title', self::SORT_ORDER_ASC);

        foreach ($values as $value) {
            $optionId = $value->getOptionId();
            if($this->getItemById($optionId)) {
                $this->getItemById($optionId)->addValue($value);
                $value->setOption($this->getItemById($optionId));
            }
        }
    }

    return $this;
} 

might be save time for someone.

OTHER TIPS

I dont see a clean way to do this.

Here is a dirty way: RewriteMage_Catalog_Model_Resource_Product_Option and add this function below. Modify it with you join. however the join to you table would then be done for every product option. You will need to check for somekind of a flag and only add your join if this flag is set.

protected function _getLoadSelect($field, $value, $object)
{ 
    $select = parent::_getLoadSelect($field, $value, $object);
    if("do your check here"){
         $select->join('your table')
    }      
    return $select;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top