本文整理汇总了PHP中Magento\Catalog\Model\Product\Type类的典型用法代码示例。如果您正苦于以下问题:PHP Type类的具体用法?PHP Type怎么用?PHP Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFactory
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);
}
示例2: toOptionArray
/**
* 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;
}
示例3: toModel
/**
* @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;
}
示例4: _prepareColumns
/**
* @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();
}
示例5: _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();
}
示例6: testGetTypeId
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();
}
示例7: getProductTypeInstance
/**
* 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];
}
示例8: getOptionArray
/**
* {@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);
}
}
示例9: configureSaveTest
/**
* 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());
}
示例10: testGetFinalPricePreset
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));
}
示例11: getDisplayOnContainers
/**
* 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;
}
示例12: getProductTypeInstances
/**
* 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;
}
示例13: execute
/**
* 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;
}
示例14: _prepareColumns
/**
* 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();
}
示例15: testGetGalleryAttributeBackend
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());
}