我安装了Magento 2.1.0。 我尝试在程序中打开每个产品页面之前更新库存状态。
我用来更新股票的代码:
// has $sku and quantity of product now
$stockItem = $this->_stockRegistry->getStockItemBySku($sku);
if($quantity > 0){
$stockItem->setQty($quantity);
$stockItem->setIsInStock(true);
}else{
$stockItem->setQty(0);
$stockItem->setIsInStock(false);
}
$this->_stockRegistry->updateStockItemBySku($sku, $stockItem);
突然之间我无法打开产品页面,原因如下:
我不知道是否因为更新了产品库存。
1 exception(s):
Exception #0 (Exception): Warning: Illegal offset type in isset or empty in D:\www_wamp_3.0.6\YingStyle\vendor\magento\module-eav\Model\Entity\Attribute\Source\AbstractSource.php on line 74
Exception #0 (Exception): Warning: Illegal offset type in isset or empty in D:\www_wamp_3.0.6\YingStyle\vendor\magento\module-eav\Model\Entity\Attribute\Source\AbstractSource.php on line 74
#0 D:\www_wamp_3.0.6\YingStyle\vendor\magento\module-eav\Model\Entity\Attribute\Source\AbstractSource.php(74): Magento\Framework\App\ErrorHandler->handler(2, 'Illegal offset ...', 'D:\\www_wamp_3.0...', 74, Array)
#1 D:\www_wamp_3.0.6\YingStyle\vendor\magento\module-eav\Model\Entity\Attribute\Frontend\AbstractFrontend.php(232): Magento\Eav\Model\Entity\Attribute\Source\AbstractSource->getOptionText(Array)
#2 D:\www_wamp_3.0.6\YingStyle\vendor\magento\module-eav\Model\Entity\Attribute\Frontend\AbstractFrontend.php(107): Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend->getOption(Array)
#3 D:\www_wamp_3.0.6\YingStyle\vendor\magento\module-catalog\Block\Product\View\Attributes.php(79): Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend->getValue(Object(Magento\Catalog\Model\Product\Interceptor))
#4 D:\www_wamp_3.0.6\YingStyle\vendor\magento\module-catalog\view\frontend\templates\product\view\attributes.phtml(19): Magento\Catalog\Block\Product\View\Attributes->getAdditionalData()
#5 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\TemplateEngine\Php.php(59): include('D:\\www_wamp_3.0...')
#6 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Element\Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\View\Attributes), 'D:/www_wamp_3.0...', Array)
#7 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Element\Template.php(279): Magento\Framework\View\Element\Template->fetchView('D:/www_wamp_3.0...')
#8 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Element\AbstractBlock.php(659): Magento\Framework\View\Element\Template->_toHtml()
#9 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(542): Magento\Framework\View\Element\AbstractBlock->toHtml()
#10 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(518): Magento\Framework\View\Layout->_renderBlock('product.attribu...')
#11 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('product.attribu...')
#12 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('product.attribu...')
#13 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(193): Magento\Framework\View\Layout->renderElement('product.attribu...', true)
#14 D:\www_wamp_3.0.6\YingStyle\app\design\frontend\Smartwave\porto\Magento_Catalog\templates\product\view\details.phtml(24): Magento\Framework\View\Layout\Interceptor->renderElement('product.attribu...')
#15 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\TemplateEngine\Php.php(59): include('D:\\www_wamp_3.0...')
#16 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Element\Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\View\Description), 'D:/www_wamp_3.0...', Array)
#17 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Element\Template.php(279): Magento\Framework\View\Element\Template->fetchView('D:/www_wamp_3.0...')
#18 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Element\AbstractBlock.php(659): Magento\Framework\View\Element\Template->_toHtml()
#19 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(542): Magento\Framework\View\Element\AbstractBlock->toHtml()
#20 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(518): Magento\Framework\View\Layout->_renderBlock('product.info.de...')
#21 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('product.info.de...')
#22 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('product.info.de...')
#23 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(193): Magento\Framework\View\Layout->renderElement('product.info.de...', true)
#24 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('product.info.de...')
#25 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(520): Magento\Framework\View\Layout->_renderContainer('content')
#26 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('content')
#27 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('content')
#28 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(193): Magento\Framework\View\Layout->renderElement('content', true)
#29 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('content')
#30 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(520): Magento\Framework\View\Layout->_renderContainer('main')
#31 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('main')
#32 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('main')
#33 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(193): Magento\Framework\View\Layout->renderElement('main', true)
#34 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('main')
#35 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(520): Magento\Framework\View\Layout->_renderContainer('columns')
#36 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('columns')
#37 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('columns')
#38 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(193): Magento\Framework\View\Layout->renderElement('columns', true)
#39 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('columns')
#40 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(520): Magento\Framework\View\Layout->_renderContainer('main.content')
#41 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('main.content')
#42 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('main.content')
#43 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(193): Magento\Framework\View\Layout->renderElement('main.content', true)
#44 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('main.content')
#45 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(520): Magento\Framework\View\Layout->_renderContainer('page.wrapper')
#46 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#47 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('page.wrapper')
#48 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(193): Magento\Framework\View\Layout->renderElement('page.wrapper', true)
#49 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('page.wrapper')
#50 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(520): Magento\Framework\View\Layout->_renderContainer('root')
#51 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('root')
#52 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('root')
#53 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(193): Magento\Framework\View\Layout->renderElement('root', true)
#54 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Layout.php(938): Magento\Framework\View\Layout\Interceptor->renderElement('root')
#55 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\Interception\Interceptor.php(146): Magento\Framework\View\Layout->getOutput()
#56 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Layout\Interceptor.php(494): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#57 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Result\Page.php(243): Magento\Framework\View\Layout\Interceptor->getOutput()
#58 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\View\Result\Layout.php(164): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#59 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#60 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#61 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-varnish-...')
#62 D:\www_wamp_3.0.6\YingStyle\vendor\magento\module-page-cache\Model\Controller\Result\VarnishPlugin.php(74): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#63 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\PageCache\Model\Controller\Result\VarnishPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#64 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-builtin-...')
#65 D:\www_wamp_3.0.6\YingStyle\vendor\magento\module-page-cache\Model\Controller\Result\BuiltinPlugin.php(67): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#66 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\Interception\Interceptor.php(142): Magento\PageCache\Model\Controller\Result\BuiltinPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#67 D:\www_wamp_3.0.6\YingStyle\var\generation\Magento\Framework\View\Result\Page\Interceptor.php(130): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#68 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\App\Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#69 D:\www_wamp_3.0.6\YingStyle\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#70 D:\www_wamp_3.0.6\YingStyle\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#71 {main}
我不知道如何解决这个问题 所以我在第74行找到了AbstractSource.php文件。
我改变了代码:
//if (isset($options[$value])) {
//return $options[$value];
//}
// new code here
if (isset($options['value'])) {
return $options['value'];
}
现在我可以再次打开产品......
但我有两个问题:
非常感谢!!!
答案 0 :(得分:1)
您获得的错误与产品页面中的选择元素无法获得正确的选项值或您提供的值无效的选项值有关。
从你的代码看,它似乎来自你如何使用setIsInStock。从magento代码块文档中,这应该是合法的,因为setIsInStock采用bool或int。但是从Magento Core代码示例中,他们使用int。例如:
setIsInStock(1)
。
你可以在这里找到一个例子:
https://github.com/magento/magento2/blob/2.1.0/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/CartItemRepositoryTest.php#L220
所以我建议你将参数从布尔值更改为整数:0
false
和1
true
。
如果能解决问题,请告诉我。
其次,我很好奇为什么你需要首先做这件事。