문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top