Magento - 调用未定义的方法 Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray

发布于 2024-11-24 15:30:24 字数 1979 浏览 1 评论 0原文

当我使用 /app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.phpsaveRow 方法访问可配置产品时,出现以下错误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,在临时数据库,然后使用 ma​​gento 在我的网站目录中添加或更新它们。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

玩心态 2024-12-01 15:30:24

在此之前:

$product->getTypeInstance()->getConfigurableAttributesAsArray($product);

检查$product->isConfigurable();。如果是,只需运行:

$product->getTypeInstance()->getConfigurableAttributesAsArray($product);

Before this:

$product->getTypeInstance()->getConfigurableAttributesAsArray($product);

Check $product->isConfigurable();. If it is, only run:

$product->getTypeInstance()->getConfigurableAttributesAsArray($product);
甜味拾荒者 2024-12-01 15:30:24

我知道这个问题很久以前就被问到了,但对于未来面临这个问题的任何人来说仍然如此。我挣扎了几乎一周并尝试了在互联网上找到的不同解决方案。最后,问题是我有一个简单的产品,其 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.

离去的眼神 2024-12-01 15:30:24

这仅适用于可配置项目,因此为此,首先检查产品是否可以使用以下代码进行配置:

if($product->isConfigurable()){
$cspa  = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
....

That's work just for configurable items, so for this, first check if product is configurable with this code:

if($product->isConfigurable()){
$cspa  = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文