首页 文章

重写Magento_GroupedProduct模型时,未发现Magento 2类错误

提问于
浏览
0

我在Magento 2.2.2中创建了一个自定义模块,它扩展了\ Magento \ GroupedProduct \ Model \ Product \ Type \ Grouped类 .

该模块已成功安装并在网站上启用,但是,我收到一个PHP致命错误:未捕获的错误:在../vendor/magento/framework/ObjectManager/Factory/中找不到类'ExtraMile \ Catalog \ Model \ Grouped' AbstractFactory.php:111 .

我的模块文件夹结构如下:

Image of module folder structure

enter image description here

di.xml 文件包含:

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'ExtraMile_GroupedProduct',
__DIR__
);

module.xml 文件包含:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  <module name="ExtraMile_GroupedProduct" setup_version="1.0.2">
    <sequence>
        <module name="Magento_GroupedProduct"/>
    </sequence>
  </module>
</config>

Grouped.php 文件包含:

<?php
namespace ExtraMile\GroupedProduct\Model;

class Grouped extends \Magento\GroupedProduct\Model\Product\Type\Grouped
{
  public function getAssociatedProducts($product)
  {
    if (!$product->hasData($this->_keyAssociatedProducts)) {
        $associatedProducts = [];

        $this->setSaleableStatus($product);

        $collection = $this->getAssociatedProductCollection(
            $product
        )->addAttributeToSelect(
            ['name', 'price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id']
        )->addFilterByRequiredOptions()->setPositionOrder()->addStoreFilter(
            $this->getStoreFilter($product)
        )->addAttributeToFilter(
            'status',
            ['in' => $this->getStatusFilters($product)]
        );

        foreach ($collection as $item) {
            $associatedProducts[] = $item;
        }

        $product->setData($this->_keyAssociatedProducts, $associatedProducts);
    }
    return $product->getData($this->_keyAssociatedProducts);
  }
}

bin/magento setup:di:compile 已多次运行 .

我已经遵循了许多教程,例如:http://inchoo.net/magento-2/overriding-classes-magento-2/,我看不出为什么我收到错误 . 请问有人可以告知问题是什么吗?

1 回答

  • 0

    问题解决了:

    我通过将模块文件夹从 app/design/frontend/<vendor>/<module> 移动到 code/<vendor>/<module> 来修复此问题 .

    运行 bin/magento setup:di:compile 然后删除了类未找到错误 .

相关问题