以前写的一个函数

在后台附加一个属性,譬如品牌

然后,在产品详细页面,把同个品牌的产品都调用出来!下面是程序代码

 

public function getOtherProduct(){
    $_producty = $this->getProduct();
    $_biaoshi = $_producty['biaoshi'];

    $resource = Mage::getSingleton('core/resource'); 
        $read = $resource->getConnection('catalog_read'); 
        $categoryProductTable = $resource->getTableName('catalog/category_product'); 
        //$productEntityIntTable = $resource->getTableName('catalog/product_entity_int'); // doesn't work
        $productEntityIntTable = (string)Mage::getConfig()->getTablePrefix().'catalog_product_entity_int'; 
        $eavAttributeTable = $resource->getTableName('eav/attribute');
        $product_attribute_valueTable = (string)Mage::getConfig()->getTablePrefix().'catalog_product_entity_varchar';
//return $product_attribute_valueTable;
       // var_dump($productEntityIntTable); exit;
       
        // Query database for featured product 
        $select = $read->select() 
                       ->from(array('cp'=>$categoryProductTable)) 
                      // ->join(array('pei'=>$productEntityIntTable),'pei.entity_id=cp.product_id', array()) 
                         ->join(array('pss'=>$product_attribute_valueTable),'pss.entity_id=cp.product_id',array())
               
                       ->joinNatural(array('ea'=>$eavAttributeTable)) 
                          //    ->joinNatural(array('pss'=>$product_attribute_valueTable))
                       // ->where('cp.category_id=?', $categoryId) 
                       ->where('pss.value=?',$_biaoshi)
                     // ->where('ea.a')
                       ->where('ea.attribute_code="biaoshi"'); 
                          ;
                       $rows = $read->fetchAll($select); 
        $ids = array();
        foreach($rows AS $row) { 
          $ids[] = $row['product_id']; 
        } 
        $ret = implode(',', $ids); 
        $ids = array_unique($ids);
       //  return $ids;
        //
        $productList = array();
        foreach($ids as $idq){
       
            $product = Mage::getModel('catalog/product')->load($idq);
            $productList[] = $product;
        }
       //  $product = Mage::getModel('catalog/product')->load($this->getProductId());
       
      //   $collection = Mage::getModel('catalog/product')->getCollection(); 
    //  $collection->getSelect()->where('e.entity_id in (?)', $ids); 
    //  $collection->addAttributeToSelect('*');
     
    //  $productList = $collection->load(); 
       
      return $productList; 
      //  return $ids; 
   
   
       
   
   
    }

如果你想成为一个magento二次开发程序员,上面的代码,你会感兴趣!