简体   繁体   English

Magento致命错误:在非对象上调用成员函数getSku()

[英]Magento Fatal Error: Call to member function getSku() on a non-object

I have come across a bizarre error in the Magento shop I'm developing and despite my inquiries online, it appears no one else has ever seen this exact error under the same circumstances. 我在开发的Magento商店中遇到一个奇怪的错误,尽管我在网上查询,但似乎没有其他人在相同的情况下看到过这种确切的错误。 Lemme 'splain. Lemme'splain。

The full text of the error message is this: 错误消息的全文是这样的:

Fatal error: Call to a member function getSku() on a non-object in /path/on/server/app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php on line 221. 致命错误:在第221行上的/path/on/server/app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php中的非对象上,调用成员函数getSku()。

Now, others have gotten this error message--it was addressed and supposedly fixed in the 1.3.1 roadmap ( http://www.magentocommerce.com/roadmap/release/1.3.1 ). 现在,其他人已经收到了此错误消息-该错误消息已在1.3.1路线图( http://www.magentocommerce.com/roadmap/release/1.3.1 )中得到解决。 However, the circumstances of those other error messages were where they tried to add an item to the cart--if the item had custom options, it would loop to this error message. 但是,这些其他错误消息的情况是他们试图将商品添加到购物车中-如果该商品具有自定义选项,它将循环到该错误信息。

My situation is that I have a SIMPLE item--not bundled or configurable--without any custom options. 我的情况是我有一个SIMPLE项-不捆绑或不可配置-没有任何自定义选项。 I can add it to the cart without any trouble. 我可以轻松地将其添加到购物车中。 But if I run through the entire checkout procedure, upon placing the order, the error message appears on a white screen. 但是,如果我执行整个结帐过程,则在下订单时,错误消息会显示在白色屏幕上。 The URL in the browser shows me I'm on the checkout success page. 浏览器中的URL显示我在结帐成功页面上。

AND, the order appears to go through perfectly, getting registered by both Magento AND Authorize.net. 而且,该订单似乎已通过Magento和Authorize.net进行了完美注册。

I've tried debugging the error as far as I can go, but this one's got me stumped. 我已经尽力尝试调试错误,但这使我感到困惑。

For reference, I'm in Magento 1.3.2.4. 供参考,我使用的是Magento 1.3.2.4。 When I first received the error I reinstalled all the core files and was still able to replicate the error. 当我第一次收到该错误时,我重新安装了所有核心文件,但仍然能够复制该错误。

I'm going to continue to test, but if anyone has ANY bright ideas about why this is happening, I'd love to hear your thoughts. 我将继续进行测试,但是如果有人对为什么会这样有任何聪明的主意,我很想听听您的想法。 I'm so close to launch and this thing could put the kibosh on the whole thing. 我离发布很近了,这东西可能会使事情变得整整齐齐。

I've had this error before and was also not getting any hits on how to solve it. 我以前遇到过此错误,并且也未获得如何解决它的任何帮助。 So, I had to modify the core files to fix the error message. 因此,我不得不修改核心文件以修复错误消息。 The problem is Mage_Catalog_Model_Product_Option::getValueById() can return a null value BUT Catalog/Model/Product/Option/Type/Select.php is NOT checking for this possibility. 问题是Mage_Catalog_Model_Product_Option::getValueById()可以返回空值,但Catalog/Model/Product/Option/Type/Select.php不检查这种可能性。

Here's the solution that worked for me: 这是对我有用的解决方案:

Open app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php 打开app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php

Change line 121 from: 将第121行更改为:

$result = $option->getValueById($optionValue)->getSku();

To: 至:

$o= $option->getValueById($optionValue);
$result = is_object($o) ? $o->getSku() : null;

I always hate changing core files but when there's a bug there's not much else I can do! 我总是讨厌更改核心文件,但是当出现错误时,我无能为力了!

I followed that steps that pygorex1 posted but also replaced lines 191-195 in the Select.php file, because I was still getting another similar error about the getPrice() . 我遵循了pygorex1发布的步骤,但是也替换了Select.php文件中的191-195行,因为我仍然遇到另一个与getPrice()类似的错误。 I have Magento ver. 我有Magento版本。 1.3.2.4. 1.3.2.4。

Original code from lines 191-195: 第191-195行的原始代码:

$result = $this->_getChargableOptionPrice(
$option->getValueById($optionValue)->getPrice(),
$option->getValueById($optionValue)->getPriceType() == 'percent',
$basePrice
);

Here is the code I created to replace lines 191-195: 这是我创建的用于替换第191-195行的代码:

$z= $option->getValueById($optionValue);
$result = is_object($z) ? $z ->getPrice() : null;

$zz = $option->getValueById($optionValue);
$result = is_object($zz) ? $zz ->getPriceType() == 'percent' : $basePrice;

FYI - I am NOT a PHP programmer. 仅供参考-我不是PHP程序员。 I just happened to figure out how to rework the code to make fix this problem based on pygorex1's code. 我只是偶然发现如何重新处理代码以基于pygorex1的代码解决此问题。 So, there is a good chance I didn't write it correctly. 因此,很有可能我没有正确编写它。 However, it did fix the problem for me (which I am rather proud of :) 但是,它确实为我解决了这个问题(对此我感到很自豪:)

Well, I had the same error for my client, Magento was working fine on one server but not on the other so I though it must be something wrong with new installation (after migration). 好吧,我的客户端也遇到了同样的错误,Magento在一台服务器上工作正常,但在另一台服务器上却无法正常工作,因此尽管新安装(迁移后)一定存在问题,但我还是错了。 I did not play with the code, just repaired the DB and it started to work properly. 我没有玩代码,只是修复了数据库,它开始正常工作。

Got same problem. 有同样的问题。 Backtraced it and identified it happens for me when editing orders in admin and that order contains at least one product with an individual option that was removed since the order has been placed. 回溯并确定了在管理员中编辑订单时发生的情况,并且该订单包含至少一种产品,该产品具有自下订单以来已删除的单个选项。

Fixed three files then so that product is simply removed when editing such an order - all modifications working in "local" scope so core files left untouched: 然后修复了三个文件,以便在编辑此类订单时只需删除产品-所有修改都在“本地”范围内进行,因此核心文件保持不变:

1. app/code/local/Mage/Catalog/Model/Product/Option/Type/Select.php:221 1. app / code / local / Mage / Catalog / Model / Product / Option / Type / Select.php:221

(search) (搜索)

$result = $option->getValueById($optionValue)->getSku();

(prepend) (前置)

/* hotfix for - PHP Fatal error:  Call to a member function getSku() on a non-object - occurs on admin order edit if a product option has been removed */
if (is_null($option->getValueById($optionValue))) {
    throw new Exception('missing product option');
}

2. app/code/local/Mage/Sales/Model/Quote.php:695 2. app / code / local / Mage / Sales / Model / Quote.php:695

(search) (搜索)

$item = $this->_addCatalogProduct($candidate, $candidate->getCartQty());

(replace) (更换)

/* hotfix for - PHP Fatal error:  Call to a member function getSku() on a non-object - occurs on admin order edit if a product option has been removed */
try {
    $item = $this->_addCatalogProduct($candidate, $candidate->getCartQty());
} catch ( Exception $e ) {
    if ($e->getMessage()=='missing product option') { return null; }
        throw new Exception($e->getMessage());
}

3. app/code/local/Mage/Adminhtml/Model/Sales/Order/Create.php:288 3. app / code / local / Mage / Adminhtml / Model / Sales / Order / Create.php:288

(search) (搜索)

if (is_string($item)) {
    return $item;
}

(replace) (更换)

if (is_string($item)) {
    return $item;
/* hotfix for - PHP Fatal error:  Call to a member function getSku() on a non-object - occurs on admin order edit if a product option has been removed */
} elseif (is_null($item)) {
    return $this;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Magento:致命错误:在非对象上调用成员函数 getMethodInstance() - Magento : Fatal error: Call to a member function getMethodInstance() on a non-object Magento致命错误-在非对象上调用成员函数getId() - Magento Fatal Error - Call to a member function getId() on a non-object Magento致命错误:在非对象上调用成员函数save() - Magento Fatal error: Call to a member function save() on a non-object 致命错误:在Magento中的非对象上调用成员函数getIdFieldName() - Fatal error: Call to a member function getIdFieldName() on a non-object in Magento 致命错误:在 magento 中的非对象上调用成员函数 getLevel() - Fatal error: Call to a member function getLevel() on a non-object in magento Magento:致命错误:在非对象上调用成员函数getItems() - Magento: Fatal error: Call to a member function getItems() on a non-object Magento:致命错误:在非对象上调用成员函数 load() - Magento: Fatal error: Call to a member function load() on a non-object 致命错误:在magento中的非对象上调用成员函数getEmail() - Fatal error: Call to a member function getEmail() on a non-object in magento Magento致命错误:在非对象上调用成员函数addFieldToFilter() - Magento Fatal error: Call to a member function addFieldToFilter() on a non-object Magento PHP致命错误:在非对象上调用成员函数setName() - Magento PHP Fatal error: Call to a member function setName() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM