函数构建问题
函数构建问题
我想在一个程序里面,调用reindex,我查过调用应该是MagentoCatalogModelIndexerProductFlatProcessor->reindexRow($id)
所以我想在程序调用它,根据老大们意思要么就在构建函数里面声明,要么就用objectManager, 但2个办法我都试了,不行,求高手们帮忙看看
class Action extends MagentoCatalogModelResourceModelAbstractResource { /** * @var MagentoCatalogModelIndexerProductFlatProcessor */ protected $_productFlatIndexerProcessor; /** * @var MagentoCatalogModelIndexerProductPriceProcessor */ protected $_productPriceIndexerProcessor; /** * Initialize connection * * @return void */ /** * @param MagentoCatalogModelIndexerProductFlatProcessor $productFlatIndexerProcessor */ protected function _construct( MagentoCatalogModelIndexerProductFlatProcessor $productFlatIndexerProcessor ) { $resource = $this->_resource; $this->_productFlatIndexerProcessor = $productFlatIndexerProcessor; $this->setType(MagentoCatalogModelProduct::ENTITY)->setConnection($resource->getConnection('catalog')); }
但这样写,程序会报错
Fatal error : Declaration of MagentoCatalogModelResourceModelProductAction::_construct(MagentoCatalogModelIndexerProductFlatProcessor $productFlatIndexerProcessor) must be compatible with MagentoFrameworkModelResourceModelAbstractResource::_construct() in /magento2/vendor/magento/module-catalog/Model/ResourceModel/Product/Action.php on line 180
但如果用objectManager的调用:
$objectManager = MagentoCatalogModelIndexerProductFlatProcessor::reindexRow(); $categoryRepository = $objectManager->create('MagentoCatalogModelResourceModelProduct');
但还是报错
Exception #0 (Exception): Deprecated Functionality: Non-static method MagentoCatalogModelIndexerProductFlatProcessor::reindexRow() should not be called statically in /home/Little/magento2/vendor/magento/module-catalog/Model/ResourceModel/Product/Action.php on line 125
求高手帮忙看看,谢谢!