Magento - 调用未定义的方法 Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray
当我使用 /app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php
saveRow 方法访问可配置产品时,出现以下错误code>:
[05-Jul-2011 18:12:32] PHP Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray() in /home/gp/public_html/app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php on line 107
我的问题与我在网上遇到的其他问题有点不同,也许是因为我从我自己的脚本调用 saveRow()
,该脚本正在构建和维护从下载的产品列表我的供应商通过 xml feed,在临时数据库,然后使用 magento 在我的网站目录中添加或更新它们。
require_once($_SERVER['DOCUMENT_ROOT']."/app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php");
$MageProducts = new Mage_Catalog_Model_Convert_Adapter_Productimport();
...
...
foreach($products as $product) {
$result = $MageProducts->saveRow($product);
}
第一次点击可配置产品时,我收到此错误,但如果我立即点击刷新,脚本将直接运行该产品并一直运行到最后,在途中传递许多简单/可配置产品集,而不会失败。
ProductImport.php 的第 107 行是这一行
$cspa = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
由于某种原因,$product->getTypeInstance
返回 Mage_Catalog_Model_Product_Type_Simple
但只是会话中第一次?!
如果我在该行之前添加 print_r($product->getTypeInstance())
,我会得到以下可配置产品的信息,
Mage_Catalog_Model_Product_Type_Simple Object ( [_product:protected] => Mage_Catalog_Model_Product Object ( [_cacheTag:protected] => catalog_product [_eventPrefix:protected] => catalog_product [_eventObject:protected] => product [_canAffectOptions:protected] => [_typeInstance:protected] => Mage_Catalog_Model_Product_Type_Simple Object *RECURSION* [_typeInstanceSingleton:protected] => Mage_Catalog_Model_Product_Type_Configurable Object ( [_usedProductAttributeIds:protected] => _cache_instance_used_product_attribute_ids....
这显然是错误的......
我希望能够通过以下方式使用我的脚本cron,但这个错误阻止我这样做,所以我迫切需要一些帮助来修复 - 谁能提供一些建议?
I'm getting the following error when I hit a configurable product using the saveRow
method from /app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php
:
[05-Jul-2011 18:12:32] PHP Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray() in /home/gp/public_html/app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php on line 107
My problem is a little different to others I've come across online perhaps in that I'm calling saveRow()
from my own script that is building and maintaining a list of products, downloaded from my supplier by xml feed, in a temporary database before then using magento to add or update them in my site's catalog.
require_once($_SERVER['DOCUMENT_ROOT']."/app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php");
$MageProducts = new Mage_Catalog_Model_Convert_Adapter_Productimport();
...
...
foreach($products as $product) {
$result = $MageProducts->saveRow($product);
}
The first time I hit a configurable product I get this error but if I immediately hit refresh the script runs right past that product and all the way through to the end, passing many simple/configurable product sets on its way, without failing.
Line 107 of ProductImport.php is this line
$cspa = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
For some reason the $product->getTypeInstance
is returning Mage_Catalog_Model_Product_Type_Simple
but only the first time in a session?!
If I add print_r($product->getTypeInstance())
just before that line I get the following for a configurable product
Mage_Catalog_Model_Product_Type_Simple Object ( [_product:protected] => Mage_Catalog_Model_Product Object ( [_cacheTag:protected] => catalog_product [_eventPrefix:protected] => catalog_product [_eventObject:protected] => product [_canAffectOptions:protected] => [_typeInstance:protected] => Mage_Catalog_Model_Product_Type_Simple Object *RECURSION* [_typeInstanceSingleton:protected] => Mage_Catalog_Model_Product_Type_Configurable Object ( [_usedProductAttributeIds:protected] => _cache_instance_used_product_attribute_ids....
Which is clearly wrong...
I want to be able to use my script through cron, but this error is stopping me from doing that so I desperately need some help to fix - can anyone offer some advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在此之前:
检查
$product->isConfigurable();
。如果是,只需运行:Before this:
Check
$product->isConfigurable();
. If it is, only run:我知道这个问题很久以前就被问到了,但对于未来面临这个问题的任何人来说仍然如此。我挣扎了几乎一周并尝试了在互联网上找到的不同解决方案。最后,问题是我有一个简单的产品,其 sku 与我尝试导入的可配置产品相同。
I know this was asked long back but still for anybody who faces this issue in future. I struggled for a week almost and tried different solution found on internet. At last here we go, the issue was i had a simple product with the same sku as the configurable product i was trying to import.
这仅适用于可配置项目,因此为此,首先检查产品是否可以使用以下代码进行配置:
That's work just for configurable items, so for this, first check if product is configurable with this code: