public function testFactory() { $product = new \Magento\Framework\DataObject(); $product->setTypeId(\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE); $type = $this->_productType->factory($product); $this->assertInstanceOf('\\Magento\\GroupedProduct\\Model\\Product\\Type\\Grouped', $type); }
/** * @param sring|null $typeId * @dataProvider factoryReturnsSingletonDataProvider */ public function testFactoryReturnsSingleton($typeId) { $product = new \Magento\Framework\DataObject(); if ($typeId) { $product->setTypeId($typeId); } $type = $this->_productType->factory($product); $otherType = $this->_productType->factory($product); $this->assertSame($otherType, $type); }
/** * Retrieve Product Type Instance * * @param string $typeId * @return \Magento\Catalog\Model\Product\Type\AbstractType */ protected function getProductTypeInstance($typeId) { if (!isset($this->productTypes[$typeId])) { $productEmulator = $this->getProductEmulator($typeId); $this->productTypes[$typeId] = $this->catalogProductType->factory($productEmulator); } return $this->productTypes[$typeId]; }
public function testFactory() { $mockedProduct = $this->getMockedProduct(); $mockedProduct->expects($this->at(0))->method('getTypeId')->will($this->returnValue('type_id_1')); $mockedProduct->expects($this->at(1))->method('getTypeId')->will($this->returnValue('type_id_3')); $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Product\\Type\\Simple', $this->_model->factory($mockedProduct)); $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Product\\Type\\Virtual', $this->_model->factory($mockedProduct)); }
/** * {@inheritdoc} */ public function factory($product) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'factory'); if (!$pluginInfo) { return parent::factory($product); } else { return $this->___callPlugins('factory', func_get_args(), $pluginInfo); } }
/** * Retrieve Product Type Instances * as key - type code, value - instance model * * @return array */ protected function getProductTypeInstances() { if (empty($this->productTypes)) { $productEmulator = new \Magento\Framework\DataObject(); foreach (array_keys($this->productType->getTypes()) as $typeId) { $productEmulator->setTypeId($typeId); $this->productTypes[$typeId] = $this->productType->factory($productEmulator); } } return $this->productTypes; }
/** * Retrieve Product Type Instances * as key - type code, value - instance model * * @return array */ protected function _getProductTypeInstances() { if ($this->_productTypes === null) { $this->_productTypes = []; $productEmulator = new \Magento\Framework\Object(); foreach (array_keys($this->_productType->getTypes()) as $typeId) { $productEmulator->setTypeId($typeId); $this->_productTypes[$typeId] = $this->_productType->factory($productEmulator); } } return $this->_productTypes; }
/** * Retrieve type instance of the product. * Type instance implements product type depended logic and is a singleton shared by all products of the same type. * * @return \Magento\Catalog\Model\Product\Type\AbstractType */ public function getTypeInstance() { if ($this->_typeInstance === null) { $this->_typeInstance = $this->_catalogProductType->factory($this); } return $this->_typeInstance; }
/** * Save type related data * * @param \Magento\Catalog\Model\Product $product * @return $this */ public function save($product) { if ($product->dataHasChangedFor('type_id') && $product->getOrigData('type_id')) { $oldTypeProduct = clone $product; $oldTypeInstance = $this->_catalogProductType->factory($oldTypeProduct->setTypeId($product->getOrigData('type_id'))); $oldTypeProduct->setTypeInstance($oldTypeInstance); $oldTypeInstance->deleteTypeSpecificData($oldTypeProduct); } return $this; }