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); }
/** * Return options. * * @return mixed */ public function toOptionArray() { $options = $this->productType->getAllOptions(); //Add default option to first key of array. First key has empty value and empty label. $options[0]['value'] = '0'; $options[0]['label'] = '---- Default Option ----'; return $options; }
/** * @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; }
/** * @return $this */ protected function _prepareColumns() { $this->addColumn('entity_id', array('header' => __('ID'), 'type' => 'number', 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id')); $this->addColumn('name', array('header' => __('Name'), 'index' => 'name', 'class' => 'xxx')); $store = $this->_getStore(); if ($store->getId()) { $this->addColumn('custom_name', array('header' => __('Name in %1', $store->getName()), 'index' => 'custom_name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name')); } $this->addColumn('type', array('header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->_type->getOptionArray())); $sets = $this->_setsFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', array('header' => __('Attribute Set'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name')); $this->addColumn('sku', array('header' => __('SKU'), 'index' => 'sku')); $store = $this->_getStore(); $this->addColumn('price', array('header' => __('Price'), 'type' => 'price', 'currency_code' => $store->getBaseCurrency()->getCode(), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price')); if ($this->_catalogData->isModuleEnabled('Magento_CatalogInventory')) { $this->addColumn('qty', array('header' => __('Quantity'), 'type' => 'number', 'index' => 'qty')); } $this->addColumn('visibility', array('header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility')); $this->addColumn('status', array('header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray())); if (!$this->_storeManager->isSingleStoreMode()) { $this->addColumn('websites', array('header' => __('Websites'), 'sortable' => false, 'index' => 'websites', 'type' => 'options', 'options' => $this->_websiteFactory->create()->getCollection()->toOptionHash(), 'header_css_class' => 'col-websites', 'column_css_class' => 'col-websites')); } $this->addColumn('edit', array('header' => __('Edit'), 'type' => 'action', 'getter' => 'getId', 'actions' => array(array('caption' => __('Edit'), 'url' => array('base' => '*/*/edit', 'params' => array('store' => $this->getRequest()->getParam('store'))), 'field' => 'id')), 'filter' => false, 'sortable' => false, 'index' => 'stores', 'header_css_class' => 'col-action', 'column_css_class' => 'col-action')); if ($this->_catalogData->isModuleEnabled('Magento_Rss')) { $this->addRssList('rss/catalog/notifystock', __('Notify Low Stock RSS')); } return parent::_prepareColumns(); }
/** * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareColumns() { $this->addColumn('entity_id', ['header' => __('ID'), 'type' => 'number', 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']); $this->addColumn('name', ['header' => __('Name'), 'index' => 'name', 'class' => 'xxx']); $store = $this->_getStore(); if ($store->getId()) { $this->addColumn('custom_name', ['header' => __('Name in %1', $store->getName()), 'index' => 'custom_name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name']); } $this->addColumn('type', ['header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->_type->getOptionArray()]); $sets = $this->_setsFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', ['header' => __('Product Template'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name']); $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']); $store = $this->_getStore(); $this->addColumn('price', ['header' => __('Price'), 'type' => 'price', 'currency_code' => $store->getBaseCurrency()->getCode(), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price']); if ($this->moduleManager->isEnabled('Magento_CatalogInventory')) { $this->addColumn('qty', ['header' => __('Quantity'), 'type' => 'number', 'index' => 'qty']); } $this->addColumn('visibility', ['header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility']); $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray()]); if (!$this->_storeManager->isSingleStoreMode()) { $this->addColumn('websites', ['header' => __('Websites'), 'sortable' => false, 'index' => 'websites', 'type' => 'options', 'options' => $this->_websiteFactory->create()->getCollection()->toOptionHash(), 'header_css_class' => 'col-websites', 'column_css_class' => 'col-websites']); } $this->addColumn('edit', ['header' => __('Edit'), 'type' => 'action', 'getter' => 'getId', 'actions' => [['caption' => __('Edit'), 'url' => ['base' => '*/*/edit', 'params' => ['store' => $this->getRequest()->getParam('store')]], 'field' => 'id']], 'filter' => false, 'sortable' => false, 'index' => 'stores', 'header_css_class' => 'col-action', 'column_css_class' => 'col-action']); $block = $this->getLayout()->getBlock('grid.bottom.links'); if ($block) { $this->setChild('grid.bottom.links', $block); } return parent::_prepareColumns(); }
public function testGetTypeId() { $productType = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\Virtual')->disableOriginalConstructor()->getMockForAbstractClass(); $this->productTypeInstanceMock->expects($this->exactly(2))->method('factory')->will($this->returnValue($productType)); $this->model->getTypeInstance(); $this->model->setTypeId('typeId'); $this->model->getTypeInstance(); }
/** * 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]; }
/** * {@inheritdoc} */ public function getOptionArray() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getOptionArray'); if (!$pluginInfo) { return parent::getOptionArray(); } else { return $this->___callPlugins('getOptionArray', func_get_args(), $pluginInfo); } }
/** * Configure environment for `testSave` and `testSaveAndDuplicate` methods * @return array */ protected function configureSaveTest() { $productTypeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\Simple')->disableOriginalConstructor()->setMethods(['beforeSave', 'save'])->getMock(); $productTypeMock->expects($this->once())->method('beforeSave')->will($this->returnSelf()); $productTypeMock->expects($this->once())->method('save')->will($this->returnSelf()); $this->productTypeInstanceMock->expects($this->once())->method('factory')->with($this->model)->will($this->returnValue($productTypeMock)); $this->model->getResource()->expects($this->any())->method('addCommitCallback')->will($this->returnSelf()); $this->model->getResource()->expects($this->any())->method('commit')->will($this->returnSelf()); }
public function testGetFinalPricePreset() { $finalPrice = 9.99; $qty = 1; $this->model->setQty($qty); $this->model->setFinalPrice($finalPrice); $this->productTypeInstanceMock->expects($this->never())->method('priceFactory'); $this->assertEquals($finalPrice, $this->model->getFinalPrice($qty)); }
/** * 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 (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; }
/** * Automaticaly assign backend model to weee attributes * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $backendModel = \Magento\Weee\Model\Attribute\Backend\Weee\Tax::getBackendModelName(); /** @var $object \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */ $object = $observer->getEvent()->getAttribute(); if ($object->getFrontendInput() == 'weee') { $object->setBackendModel($backendModel); if (!$object->getApplyTo()) { $applyTo = []; foreach ($this->productType->getOptions() as $option) { if ($this->productTypeConfig->isProductSet($option['value'])) { continue; } $applyTo[] = $option['value']; } $object->setApplyTo($applyTo); } } return $this; }
/** * Prepare grid columns * * @return $this */ protected function _prepareColumns() { $this->addColumn('id', ['header' => __('ID'), 'sortable' => true, 'width' => '60px', 'index' => 'entity_id']); $this->addColumn('name', ['header' => __('Product'), 'index' => 'name', 'column_css_class' => 'name']); $sets = $this->_eavCollectionFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('type', ['header' => __('Type'), 'width' => '60px', 'index' => 'type_id', 'type' => 'options', 'options' => $this->_productType->getOptionArray()]); $this->addColumn('set_name', ['header' => __('Attribute Set'), 'width' => '100px', 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets]); $this->addColumn('sku', ['header' => __('SKU'), 'width' => '80px', 'index' => 'sku', 'column_css_class' => 'sku']); $this->addColumn('price', ['header' => __('Price'), 'align' => 'center', 'type' => 'currency', 'currency_code' => $this->_getStore()->getDefaultCurrencyCode(), 'rate' => $this->_getStore()->getBaseCurrency()->getRate($this->_getStore()->getDefaultCurrencyCode()), 'index' => 'price']); return parent::_prepareColumns(); }
public function testGetGalleryAttributeBackend() { $productType = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\AbstractType')->setMethods(['getEditableAttributes'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->productTypeInstanceMock->expects($this->any())->method('factory')->will($this->returnValue($productType)); $attributeMediaGallery = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->setMethods(['__wakeup', 'getAttributeCode', 'getBackend'])->disableOriginalConstructor()->getMockForAbstractClass(); $attributeMediaGallery->expects($this->any())->method('getAttributeCode')->willReturn('media_gallery'); $expectedValue = 'expected'; $attributeMediaGallery->expects($this->once())->method('getBackend')->willReturn($expectedValue); $productType->expects($this->once())->method('getEditableAttributes')->willReturn(['media_gallery' => $attributeMediaGallery]); $this->assertEquals($expectedValue, $this->model->getGalleryAttributeBackend()); }
/** * Define Cooser Grid Columns and filters * * @return $this */ protected function _prepareColumns() { $this->addColumn('in_products', array('header_css_class' => 'a-center', 'type' => 'checkbox', 'name' => 'in_products', 'values' => $this->_getSelectedProducts(), 'align' => 'center', 'index' => 'sku', 'use_index' => true)); $this->addColumn('entity_id', array('header' => __('ID'), 'sortable' => true, 'width' => '60px', 'index' => 'entity_id')); $this->addColumn('type', array('header' => __('Type'), 'width' => '60px', 'index' => 'type_id', 'type' => 'options', 'options' => $this->_catalogType->getOptionArray())); $sets = $this->_eavAttSetCollection->create()->setEntityTypeFilter($this->_catalogProduct->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', array('header' => __('Attribute Set'), 'width' => '100px', 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets)); $this->addColumn('chooser_sku', array('header' => __('SKU'), 'name' => 'chooser_sku', 'width' => '80px', 'index' => 'sku')); $this->addColumn('chooser_name', array('header' => __('Product'), 'name' => 'chooser_name', 'index' => 'name')); return parent::_prepareColumns(); }
/** * Retrieve Stock Indexer Models per Product Type * * @return \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\StockInterface[] */ protected function _getTypeIndexers() { if (empty($this->_indexers)) { foreach ($this->_catalogProductType->getTypesByPriority() as $typeId => $typeInfo) { $indexerClassName = isset($typeInfo['stock_indexer']) ? $typeInfo['stock_indexer'] : ''; $indexer = $this->_indexerFactory->create($indexerClassName)->setTypeId($typeId)->setIsComposite(!empty($typeInfo['composite'])); $this->_indexers[$typeId] = $indexer; } } return $this->_indexers; }
/** * 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; }
/** * Add ordered qty's * * @param string $from * @param string $to * @return $this */ public function addOrderedQty($from = '', $to = '') { $adapter = $this->getConnection(); $compositeTypeIds = $this->_productType->getCompositeTypes(); $orderTableAliasName = $adapter->quoteIdentifier('order'); $orderJoinCondition = array($orderTableAliasName . '.entity_id = order_items.order_id', $adapter->quoteInto("{$orderTableAliasName}.state <> ?", \Magento\Sales\Model\Order::STATE_CANCELED)); $productJoinCondition = array($adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds), 'e.entity_id = order_items.product_id', $adapter->quoteInto('e.entity_type_id = ?', $this->getProductEntityTypeId())); if ($from != '' && $to != '') { $fieldName = $orderTableAliasName . '.created_at'; $orderJoinCondition[] = $this->_prepareBetweenSql($fieldName, $from, $to); } $this->getSelect()->reset()->from(array('order_items' => $this->getTable('sales_flat_order_item')), array('ordered_qty' => 'SUM(order_items.qty_ordered)', 'order_items_name' => 'order_items.name'))->joinInner(array('order' => $this->getTable('sales_flat_order')), implode(' AND ', $orderJoinCondition), array())->joinLeft(array('e' => $this->getProductEntityTableName()), implode(' AND ', $productJoinCondition), array('entity_id' => 'order_items.product_id', 'entity_type_id' => 'e.entity_type_id', 'attribute_set_id' => 'e.attribute_set_id', 'type_id' => 'e.type_id', 'sku' => 'e.sku', 'has_options' => 'e.has_options', 'required_options' => 'e.required_options', 'created_at' => 'e.created_at', 'updated_at' => 'e.updated_at'))->where('parent_item_id IS NULL')->group('order_items.product_id')->having('SUM(order_items.qty_ordered) > ?', 0); return $this; }
/** * Retrieve price indexers per product type * * @return \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\PriceInterface[] */ public function getTypeIndexers() { if ($this->_indexers === null) { $this->_indexers = []; $types = $this->_catalogProductType->getTypesByPriority(); foreach ($types as $typeId => $typeInfo) { $modelName = isset($typeInfo['price_indexer']) ? $typeInfo['price_indexer'] : get_class($this->_defaultIndexerResource); $isComposite = !empty($typeInfo['composite']); $indexer = $this->_indexerPriceFactory->create($modelName)->setTypeId($typeId)->setIsComposite($isComposite); $this->_indexers[$typeId] = $indexer; } } return $this->_indexers; }
/** * Add columns to grid * * @return $this */ protected function _prepareColumns() { if (!$this->getProduct()->getUpsellReadonly()) { $this->addColumn('in_products', array('type' => 'checkbox', 'name' => 'in_products', 'values' => $this->_getSelectedProducts(), 'align' => 'center', 'index' => 'entity_id', 'header_css_class' => 'col-select', 'column_css_class' => 'col-select')); } $this->addColumn('entity_id', array('header' => __('ID'), 'sortable' => true, 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id')); $this->addColumn('name', array('header' => __('Name'), 'index' => 'name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name')); $this->addColumn('type', array('header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->_type->getOptionArray(), 'header_css_class' => 'col-type', 'column_css_class' => 'col-type')); $sets = $this->_setsFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', array('header' => __('Attribute Set'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name')); $this->addColumn('status', array('header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray(), 'header_css_class' => 'col-status', 'column_css_class' => 'col-status')); $this->addColumn('visibility', array('header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility')); $this->addColumn('sku', array('header' => __('SKU'), 'index' => 'sku', 'header_css_class' => 'col-sku', 'column_css_class' => 'col-sku')); $this->addColumn('price', array('header' => __('Price'), 'type' => 'currency', 'currency_code' => (string) $this->_scopeConfig->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price')); $this->addColumn('position', array('header' => __('Position'), 'name' => 'position', 'type' => 'number', 'validate_class' => 'validate-number', 'index' => 'position', 'editable' => !$this->getProduct()->getUpsellReadonly(), 'edit_only' => !$this->getProduct()->getId(), 'header_css_class' => 'col-position', 'column_css_class' => 'col-position', 'filter_condition_callback' => array($this, 'filterProductPosition'))); return parent::_prepareColumns(); }
/** * @return $this */ protected function _prepareColumns() { $this->addColumn('in_products', ['header_css_class' => 'a-center', 'type' => 'checkbox', 'name' => 'in_products', 'values' => $this->_getSelectedProducts(), 'align' => 'center', 'index' => 'entity_id']); $this->addColumn('entity_id', ['header' => __('ID'), 'sortable' => true, 'index' => 'entity_id', 'type' => 'number', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']); $this->addColumn('name', ['header' => __('Name'), 'index' => 'product_name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name']); $this->addColumn('type', ['header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->type->getOptionArray(), 'header_css_class' => 'col-type', 'column_css_class' => 'col-type']); /** @var \Magento\Catalog\Model\Resource\Product $resource */ $resource = $this->productFactory->create()->getResource(); $sets = $this->setCollectionFactory->create()->setEntityTypeFilter($resource->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', ['header' => __('Attribute Set'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name']); $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->status->getOptionArray(), 'header_css_class' => 'col-status', 'column_css_class' => 'col-status']); $this->addColumn('visibility', ['header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility']); $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku', 'header_css_class' => 'col-sku', 'column_css_class' => 'col-sku']); $this->addColumn('price', ['header' => __('Price'), 'type' => 'currency', 'currency_code' => (string) $this->_scopeConfig->getValue(Currency::XML_PATH_CURRENCY_BASE, ScopeInterface::SCOPE_STORE), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price']); $this->addColumn('position', ['header' => __('Position'), 'name' => 'position', 'width' => 60, 'type' => 'number', 'validate_class' => 'validate-number', 'index' => 'position', 'editable' => true]); return $this; }
/** * Prepare group prices data for website * * @param array $priceData * @param string $productTypeId * @param int $websiteId * @return array */ public function preparePriceData(array $priceData, $productTypeId, $websiteId) { $rates = $this->_getWebsiteCurrencyRates(); $data = []; $price = $this->_catalogProductType->priceFactory($productTypeId); foreach ($priceData as $v) { $key = join('-', array_merge([$v['cust_group']], $this->_getAdditionalUniqueFields($v))); if ($v['website_id'] == $websiteId) { $data[$key] = $v; $data[$key]['website_price'] = $v['price']; } elseif ($v['website_id'] == 0 && !isset($data[$key])) { $data[$key] = $v; $data[$key]['website_id'] = $websiteId; if ($this->_isPriceFixed($price)) { $data[$key]['price'] = $v['price'] * $rates[$websiteId]['rate']; $data[$key]['website_price'] = $v['price'] * $rates[$websiteId]['rate']; } } } return $data; }
public function testGetTypesByPriority() { $types = $this->_productType->getTypesByPriority(); // collect the types and priority in the same order as the method returns $result = []; foreach ($types as $typeId => $type) { if (!isset($type['index_priority'])) { // possible bug: index_priority is not defined for each type $priority = 0; } else { $priority = (int) $type['index_priority']; } // non-composite must be before composite if (1 != $type['composite']) { $priority = -1 * $priority; } $result[$typeId] = $priority; } $expectedResult = $result; asort($expectedResult); $this->assertEquals($expectedResult, $result); }
/** * Get product Price Info object * * @return \Magento\Framework\Pricing\PriceInfo\Base */ public function getPriceInfo() { if (!$this->_priceInfo) { $this->_priceInfo = $this->_catalogProductType->getPriceInfo($this); } return $this->_priceInfo; }
/** * 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; }
public function testPriceFactory() { $this->assertInstanceOf('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Price', $this->_model->priceFactory('type_id_3')); $this->assertInstanceOf('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Price', $this->_model->priceFactory('type_id_3')); $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Product\\Type\\Price', $this->_model->priceFactory('type_id_1')); }