Example #1
0
 public function testGetTypes()
 {
     $property = new \ReflectionProperty($this->_model, '_types');
     $property->setAccessible(true);
     $this->assertNull($property->getValue($this->_model));
     $this->assertEquals($this->_productTypes, $this->_model->getTypes());
 }
Example #2
0
 /**
  * @param  Product $product
  * @param  \Magento\Catalog\Model\Product $productModel
  * @return \Magento\Catalog\Model\Product
  * @throws \RuntimeException
  */
 public function toModel(Product $product, \Magento\Catalog\Model\Product $productModel = null)
 {
     /** @var \Magento\Catalog\Model\Product $productModel */
     $productModel = $productModel ?: $this->productFactory->create();
     $productModel->addData(ExtensibleDataObjectConverter::toFlatArray($product));
     if (!is_numeric($productModel->getAttributeSetId())) {
         $productModel->setAttributeSetId($productModel->getDefaultAttributeSetId());
     }
     if (!$productModel->hasTypeId()) {
         $productModel->setTypeId(\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE);
     } elseif (!isset($this->productTypes->getTypes()[$productModel->getTypeId()])) {
         throw new \RuntimeException('Illegal product type');
     }
     return $productModel;
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * Generate array of parameters for every container type to create html template
  *
  * @return array
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function getDisplayOnContainers()
 {
     $container = [];
     $container['anchor'] = ['label' => 'Categories', 'code' => 'categories', 'name' => 'anchor_categories', 'layout_handle' => \Magento\Widget\Model\Widget\Instance::ANCHOR_CATEGORY_LAYOUT_HANDLE, 'is_anchor_only' => 1, 'product_type_id' => ''];
     $container['notanchor'] = ['label' => 'Categories', 'code' => 'categories', 'name' => 'notanchor_categories', 'layout_handle' => \Magento\Widget\Model\Widget\Instance::NOTANCHOR_CATEGORY_LAYOUT_HANDLE, 'is_anchor_only' => 0, 'product_type_id' => ''];
     $container['all_products'] = ['label' => 'Products', 'code' => 'products', 'name' => 'all_products', 'layout_handle' => \Magento\Widget\Model\Widget\Instance::PRODUCT_LAYOUT_HANDLE, 'is_anchor_only' => '', 'product_type_id' => ''];
     foreach ($this->_productType->getTypes() as $typeId => $type) {
         $container[$typeId] = ['label' => 'Products', 'code' => 'products', 'name' => $typeId . '_products', 'layout_handle' => str_replace('{{TYPE}}', $typeId, \Magento\Widget\Model\Widget\Instance::PRODUCT_TYPE_LAYOUT_HANDLE), 'is_anchor_only' => '', 'product_type_id' => $typeId];
     }
     return $container;
 }
 /**
  * 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;
 }
Example #6
0
 public function testGetTypes()
 {
     $types = $this->_productType->getTypes();
     $this->assertArrayHasKey(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, $types);
     $this->assertArrayHasKey(\Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL, $types);
     $this->assertArrayHasKey(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE, $types);
     $this->assertArrayHasKey(\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE, $types);
     foreach ($types as $type) {
         $this->assertArrayHasKey('label', $type);
         $this->assertArrayHasKey('model', $type);
         $this->assertArrayHasKey('composite', $type);
         // possible bug: index_priority is not defined for each type
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getTypes()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getTypes');
     if (!$pluginInfo) {
         return parent::getTypes();
     } else {
         return $this->___callPlugins('getTypes', func_get_args(), $pluginInfo);
     }
 }