2016-05-14 5 views
0

「私は、ローカルフォルダにCompareController.phpをオーバーライドしましたが、その後、動作していない私は、コントローラとのMagentoのコアCompareController.phpコントローラが、その後もaddtocompare機能は同じカテゴリの商品をマジェンタで比較するには?

<?php 

//notice that require_once is calling **CompareController.php** under the Product directory 
    require_once(Mage::getModuleDir('controllers','Mage_Catalog').DS.'Product'.DS.'CompareController.php'); 

class Company_Catalog_Product_CompareController extends Mage_Catalog_Product_CompareController 
{ 
public function addAction() { 

    if (!$this->_validateFormKey()) { 
     $this->_redirectReferer(); 
     return; 
    } 

    $productId = (int) $this->getRequest()->getParam('product'); 

    $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId); 

    $categoryIds = $product->getCategoryIds(); 

    $productPresent = false; 
    $found = array(); 
    $compareProducts = Mage::helper('catalog/product_compare')->getItemCollection(); 

    $itemCount = Mage::helper('catalog/product_compare')->getItemCount(); 


    if($itemCount) { 
     $compareProductId = $compareProducts->getFirstItem()->getId(); 
     $compareProductCollection = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($compareProductId); 
     $compareProductCats = $compareProductCollection->getCategoryIds(); 

     foreach($categoryIds as $num) { 
      if (in_array($num,$compareProductCats)) { 
       $found[$num] = true; 
      } 
     } 

     foreach($compareProducts as $products) { 
      if($productId == $products->getId()) { 
       $productPresent = true; 
      } 
     } 

     //Check if categories of products to be compared are matching 
     if(empty($found)){ 
      Mage::getSingleton('catalog/session')->addError(
       $this->__('You cannot compare %s with the items in the comparison list. Please select products from the same category.', Mage::helper('core')->escapeHtml($product->getName())) 
      ); 
      $this->_redirectReferer(); 
      return; 
     }    

    } 

    //Add product in comparison list 
    if ($productId && (Mage::getSingleton('log/visitor')->getId() || Mage::getSingleton('customer/session')->isLoggedIn())) { 

     if ($product->getId()/* && !$product->isSuper()*/) { 
      Mage::getSingleton('catalog/product_compare_list')->addProduct($product); 
      Mage::getSingleton('catalog/session')->addSuccess(
       $this->__('The product %s has been added to the comparison list.', Mage::helper('core')->escapeHtml($product->getName())) 
      ); 
      Mage::dispatchEvent('catalog_product_compare_add_product', array('product'=>$product)); 
     } 

     Mage::helper('catalog/product_compare')->calculate(); 
    } 

    $this->_redirectReferer(); 
} 
} 

?> 
+0

は何ですかあなたが持っている正確な問題?あなたが得ている完全なエラーメッセージと、すでに問題を解決しようとしたものを投稿してください。 – codedge

+0

今はうまく働いています.... thnx –

答えて

0

することができますが働いているの両方の名前を変更しますこのようにコントローラを無効にします。 Magentoクラスローダーがコントローラクラスのローカルフォルダを探していません。

しかし、あなたがしたいコントローラウィッヒアクションはこのため を上書きする前に、あなたはあなたが新しいコントローラとモジュールを所有し、config.xmlにこの行を追加作成する必要がある独自のcontollerの呼び出しを追加することができます

<config> 
... 
<frontend> 
    <routers> 
     <catalog> 
      <args> 
       <modules> 
        <MyModule_Compare before="Mage_Catalog">MyModule_Compare</MyModule_Compare> 
       </modules> 
      </args> 
     </catalog> 
    </routers> 
</frontend> 
... 
</config> 
+0

OKこれを試してみましたが、うまくいきませんでした。 –

+0

これは100%の仕事かもしれません/ –

+0

実際に働いています......実際にそれは別の内線と衝突していた –

関連する問題