/** * Retrieve list of product templates with search part contained in label * * @param string $labelPart * @return array */ public function getSuggestedTemplates($labelPart) { $product = $this->_coreRegistry->registry('product'); $entityType = $product->getResource()->getEntityType(); $labelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']); /** @var \Magento\Eav\Model\Resource\Entity\Attribute\Set\Collection $collection */ $collection = $this->_setColFactory->create(); $collection->setEntityTypeFilter($entityType->getId())->addFieldToFilter('attribute_set_name', ['like' => $labelPart])->addFieldToSelect('attribute_set_id', 'id')->addFieldToSelect('attribute_set_name', 'label')->setOrder('attribute_set_name', \Magento\Eav\Model\Resource\Entity\Attribute\Set\Collection::SORT_ORDER_ASC); return $collection->getData(); }
/** * {@inheritdoc} */ public function getList() { $sets = array(); $attributeSetsCollection = $this->setCollectionFactory->create()->setEntityTypeFilter($this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId())->load(); /** @var $attributeSet \Magento\Eav\Model\Resource\Entity\Attribute\Set */ foreach ($attributeSetsCollection as $attributeSet) { $this->attributeSetBuilder->setId($attributeSet->getId()); $this->attributeSetBuilder->setName($attributeSet->getAttributeSetName()); $this->attributeSetBuilder->setSortOrder($attributeSet->getSortOrder()); $sets[] = $this->attributeSetBuilder->create(); } return $sets; }
/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { /** @var \Magento\Eav\Model\Resource\Entity\Attribute\Set\Collection $collection */ $collection = $this->collectionFactory->create(); /** The only possible/meaningful search criteria for attribute set is entity type code */ $entityTypeCode = $this->getEntityTypeCode($searchCriteria); if ($entityTypeCode !== null) { $collection->setEntityTypeFilter($this->eavConfig->getEntityType($entityTypeCode)->getId()); } $collection->setCurPage($searchCriteria->getCurrentPage()); $collection->setPageSize($searchCriteria->getPageSize()); $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($searchCriteria); $searchResults->setItems($collection->getItems()); $searchResults->setTotalCount($collection->getSize()); return $searchResults; }
/** * 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(); }
/** * 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(); }
/** * @return $this */ public function loadAttributeSets() { if ($this->_attributeSetsById) { return $this; } $attributeSetCollection = $this->_setCollectionFactory->create()->load(); $this->_attributeSetsById = []; $this->_attributeSetsByName = []; foreach ($attributeSetCollection as $id => $attributeSet) { $entityTypeId = $attributeSet->getEntityTypeId(); $name = $attributeSet->getAttributeSetName(); $this->_attributeSetsById[$entityTypeId][$id] = $name; $this->_attributeSetsByName[$entityTypeId][strtolower($name)] = $id; } return $this; }
/** * Initialize attributes parameters for all attributes' sets. * * @return $this */ protected function _initAttributes() { // temporary storage for attributes' parameters to avoid double querying inside the loop $attributesCache = []; foreach ($this->_attrSetColFac->create()->setEntityTypeFilter($this->_entityModel->getEntityTypeId()) as $attributeSet) { foreach ($this->_prodAttrColFac->create()->setAttributeSetFilter($attributeSet->getId()) as $attribute) { $attributeCode = $attribute->getAttributeCode(); $attributeId = $attribute->getId(); if ($attribute->getIsVisible() || in_array($attributeCode, $this->_forcedAttributesCodes)) { if (!isset($attributesCache[$attributeId])) { $attributesCache[$attributeId] = ['id' => $attributeId, 'code' => $attributeCode, 'is_global' => $attribute->getIsGlobal(), 'is_required' => $attribute->getIsRequired(), 'is_unique' => $attribute->getIsUnique(), 'frontend_label' => $attribute->getFrontendLabel(), 'is_static' => $attribute->isStatic(), 'apply_to' => $attribute->getApplyTo(), 'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute), 'default_value' => strlen($attribute->getDefaultValue()) ? $attribute->getDefaultValue() : null, 'options' => $this->_entityModel->getAttributeOptions($attribute, $this->_indexValueAttributes)]; } $this->_addAttributeParams($attributeSet->getAttributeSetName(), $attributesCache[$attributeId], $attribute); } } } return $this; }
/** * Get array with attribute setes which available for some target country * * @param string $targetCountry * @return array */ protected function _getAttributeSetsArray($targetCountry) { $entityType = $this->_productFactory->create()->getResource()->getEntityType(); $collection = $this->_eavCollectionFactory->create()->setEntityTypeFilter($entityType->getId()); $ids = []; $itemType = $this->getItemType(); if (!($itemType instanceof \Magento\Framework\Object && $itemType->getId())) { $typesCollection = $this->_typeCollectionFactory->create()->addCountryFilter($targetCountry)->load(); foreach ($typesCollection as $type) { $ids[] = $type->getAttributeSetId(); } } $result = ['' => '']; foreach ($collection as $attributeSet) { if (!in_array($attributeSet->getId(), $ids)) { $result[$attributeSet->getId()] = $attributeSet->getAttributeSetName(); } } return $result; }
/** * Initialize attribute sets code-to-id pairs. * * @return $this */ protected function _initAttributeSets() { foreach ($this->_setColFactory->create()->setEntityTypeFilter($this->_entityTypeId) as $attributeSet) { $this->_attrSetNameToId[$attributeSet->getAttributeSetName()] = $attributeSet->getId(); $this->_attrSetIdToName[$attributeSet->getId()] = $attributeSet->getAttributeSetName(); } return $this; }