/** * Retrieve options for 'Add Product' split button * * @return array */ protected function _getAddProductButtonOptions() { $splitButtonOptions = []; $types = $this->_typeFactory->create()->getTypes(); uasort($types, function ($elementOne, $elementTwo) { return $elementOne['sort_order'] < $elementTwo['sort_order'] ? -1 : 1; }); foreach ($types as $typeId => $type) { $splitButtonOptions[$typeId] = ['label' => __($type['label']), 'onclick' => "setLocation('" . $this->_getProductCreateUrl($typeId) . "')", 'default' => \Magento\Catalog\Model\Product\Type::DEFAULT_TYPE == $typeId]; } return $splitButtonOptions; }
/** * Constructor. * * @param ResourceModel $resourceModel Resource model * @param ProductTypeFactory $productTypeFactory Product type factory (used to detect products types). */ public function __construct(ResourceModel $resourceModel, ProductTypeFactory $productTypeFactory) { $this->resourceModel = $resourceModel; $this->productType = $productTypeFactory->create(); }
/** * @return $this */ public function loadProductTypes() { if ($this->_productTypesById) { return $this; } $productTypeCollection = $this->_productTypeFactory->create()->getOptionArray(); $this->_productTypesById = array(); $this->_productTypesByName = array(); foreach ($productTypeCollection as $id => $type) { $name = $type; $this->_productTypesById[$id] = $name; $this->_productTypesByName[strtolower($name)] = $id; } return $this; }