doubi1624 2014-03-25 12:55
浏览 22
已采纳

Magento帮助(PHP)

I've recently tried to run a Magento extension on 1.8 - The extension isn't compatible with this version. However, I'm trying to work out a fix around the compatibility issues, so if anybody has any input that would be great.

The error itself says:

Invalid argument supplied for foreach() in /app/code/community/Anais/Accessories/Block/Adminhtml/Catalog/Product/Edit/Tab/Accessories.php on line 254

The foreach block is:

foreach (Mage::registry('current_product')->getAccessoriesProducts() as $product) {
    $products[$product->getId()] = array('position' => $product->getPosition());
}

Alternatively, if anybody can recommend an extension for Product Accessories that would be handy.

  • 写回答

1条回答 默认 最新

  • dongmo6937 2014-03-25 13:14
    关注

    I've just tested the extension on CE-1.8.1 and it runs smoothly.
    Clear the cache and disable compilation and try again.
    Also keep in mind that the extension rewrites the Mage_Catalog_Model_Product class (the product model).

    I know it's not a good approach (not my best work I might say - but I developed this while I was still learning a lot). Check if you have other extensions that rewrite that model.

    You can check with a simple php code that looks like this.

    echo get_class(Mage::getModel('catalog/product'));
    

    If what you get printed is Mage_Catalog_Model_Product then it must be a cache problem.

    If you get Anais_Accessories_Model_Product then there is something wrong with the extension indeed.

    If you get something else, for example Namespace_Module_Catalog_Product then you have an other extension that rewrites the product model.

    In order to fix this you need to make the Anais_Accessories extension depend on the extension that rewrites the product model.
    For this add the following in app/etc/modules/Anais_Accessories.xml as a sibling for the <active> tag.

    <depends>
        <Namespace_Module /> <!-- put here the name of the extension that rewrites the product model -->
    </depends>
    

    Then you need to make the product model in the Anais_Accessories extension extend the model you got from the echo statement above.

    Edit app/code/community/Anais/Accessories/Model/Product.php and replace

    class Anais_Accessories_Model_Product extends Mage_Catalog_Model_Product{
    

    with

    class Anais_Accessories_Model_Product extends Namespace_Module_Catalog_Product{ //make it extend the value you got from the echo statement above. 
    

    There...this should cover all the cases and you still get to keep and use your other extension that rewrites the product model (if you have one).

    [EDIT]

    A bit off topic, but it's too long to fit in a comment:

    For a fast import of product relations I can recommend you this extension: https://github.com/tzyganu/ProductRelationsImport. It works with only the default Magento relations (related, crosssels, upsells) but you can easily add an other type pf relation. Just edit the method getAllOptions from app/code/community/Easylife/Relations/Model/Import/Relation.php and add a new relation like the others.

    $this->_options[] = array(
        'label' => Mage::helper('easylife_relations')->__('Accessories'),
        'value' => Anais_Accessories_Model_Product_Link::LINK_TYPE_ACCESSORIES,
    );
    

    But backup your db before trying it. It is still in beta.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置