option value magento

piaoling  2011-11-21 15:42:42

<?php
class Bysoft_Catalog_Model_Adminhtml_Product extends Mage_Core_Model_Abstract{
    public function getProductOptionArray($code,$storeId=0){
        $option= array();
        $entityTypeId=$this->getEntityTypeId('catalog_product');
        $data = $this->prepareOptionData($code,$entityTypeId);
        if(is_array($data)){
            foreach ($data as $item){
                $optionId = $item['option_id'];
                $storeOptionId =$item['store_id'];
                $option[$optionId][$storeOptionId]=$item['valuedata'];
            }
        }
        $newOption=array();
        foreach($option as $optionKey=>$item){
            if(isset($option[$optionKey][$storeId])){
                $newOption[$optionKey]=$option[$optionKey][$storeId];
            }else{
                $newOption[$optionKey]=$option[$optionKey][0];
            }
        }
        return $newOption;
    }
    public function prepareOptionData($attributeCode,$entityTypeId){
        $sql = "select ovalue.value as valuedata,ovalue.option_id,ovalue.store_id as store_id from eav_attribute  as e inner join eav_attribute_option as eoption on eoption.attribute_id = e.attribute_id inner join eav_attribute_option_value as ovalue on ovalue.option_id=eoption.option_id
                where e.attribute_code='$attributeCode' and entity_type_id ='$entityTypeId'";
        $connection = Mage::getSingleton('core/resource')->getConnection('core_read');;
        $data = $connection->fetchAll($sql);
        return $data;
    }
    public function getAttributeId($entity_type,$code){
        $attri= Mage::getModel('eav/entity_attribute')->loadByCode($entity_type,$code);
        return $attri->getId();
    }
    public function getEntityTypeId($code){
        $entity= Mage::getModel('eav/entity_type')->loadByCode($code);
        return $entity->getId();
    }
}

类别 :  magento(258)  |  浏览(3664)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: