2015-09-04 139 views
1

我正在嘗試編寫一個腳本來創建可配置的產品。我一直用這個作爲指導:http://inchoo.net/magento/programmatically-create-a-configurable-magento-product/Magento getConfigurableAttributesAsArray導致致命錯誤

當我到了這一行:

$configurableAttributesData = $configProduct->getTypeInstance()->getConfigurableAttributesAsArray(); 

腳本崩潰,並踢了這個錯誤:

Fatal error: Call to a member function getId() on a non-object in /home/buyfrom/public_html/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php on line 283 

a comment on this page,我改變了線到以下:

$possibleAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product); 

但我仍然得到是錯誤的。任何人都可以建議如何解決此問題?

回答

0

確保您選擇的屬性集(例如默認值)至少具有一個可配置屬性(例如:'color'或'size')。

+1

這不提供一個問題的答案,應該是一個評論。請參閱[我應該何時評論?](https://stackoverflow.com/help/privileges/comment)。 一旦你有足夠的[聲望](https://stackoverflow.com/help/whats-reputation),你將可以在任何帖子上[評論](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提問者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 – Dwhitz