/**
  * Return options for select
  *
  * @return array
  */
 public function getOptions()
 {
     /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection */
     $collection = $this->attributeSetCollectionFactory->create();
     $collection->setEntityTypeFilter($this->locator->getProduct()->getResource()->getTypeId())->addFieldToSelect('attribute_set_id', 'value')->addFieldToSelect('attribute_set_name', 'label')->setOrder('attribute_set_name', \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection::SORT_ORDER_ASC);
     return $collection->getData();
 }
示例#2
0
 /**
  * Retrieve list of product attribute sets with search part contained in label
  *
  * @param string $labelPart
  * @return array
  */
 public function getSuggestedSets($labelPart)
 {
     $labelPart = $this->resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
     /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection */
     $collection = $this->attributeSetCollectionFactory->create();
     $collection->setEntityTypeFilter($this->product->getTypeId())->addFieldToFilter('attribute_set_name', ['like' => $labelPart])->addFieldToSelect('attribute_set_id', 'id')->addFieldToSelect('attribute_set_name', 'label')->setOrder('attribute_set_name', \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection::SORT_ORDER_ASC);
     return $collection->getData();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->attributeSetCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->attributeSetCollectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
     $this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)->disableOriginalConstructor()->getMock();
     $this->productResourceMock = $this->getMockBuilder(ProductResource::class)->disableOriginalConstructor()->getMock();
     $this->attributeSetCollectionFactoryMock->expects($this->any())->method('create')->willReturn($this->attributeSetCollectionMock);
     $this->productMock->expects($this->any())->method('getResource')->willReturn($this->productResourceMock);
     $this->attributeSetCollectionMock->expects($this->any())->method('setEntityTypeFilter')->willReturnSelf();
     $this->attributeSetCollectionMock->expects($this->any())->method('addFieldToSelect')->willReturnSelf();
 }
 /**
  * Get action options
  *
  * @return array
  */
 public function jsonSerialize()
 {
     if ($this->options === null) {
         $options = $this->collectionFactory->create()->setEntityTypeFilter($this->product->getEntityType()->getEntityTypeId())->toOptionArray();
         $this->prepareData();
         foreach ($options as $optionCode) {
             $this->options[$optionCode['value']] = ['type' => 'customer_group_' . $optionCode['value'], 'label' => $optionCode['label']];
             if ($this->urlPath && $this->paramName) {
                 $this->options[$optionCode['value']]['url'] = $this->urlBuilder->getUrl($this->urlPath, [$this->paramName => $optionCode['value']]);
             }
             $this->options[$optionCode['value']] = array_merge_recursive($this->options[$optionCode['value']], $this->additionalData);
         }
         $this->options = array_values($this->options);
     }
     return $this->options;
 }
 /**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection */
     $collection = $this->collectionFactory->create();
     $this->joinProcessor->process($collection);
     /** 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;
 }
示例#6
0
 /**
  * Define Cooser Grid Columns and filters
  *
  * @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' => 'sku', 'use_index' => true]);
     $this->addColumn('entity_id', ['header' => __('ID'), 'sortable' => true, 'width' => '60px', 'index' => 'entity_id']);
     $this->addColumn('type', ['header' => __('Type'), 'width' => '60px', 'index' => 'type_id', 'type' => 'options', 'options' => $this->_catalogType->getOptionArray()]);
     $sets = $this->_eavAttSetCollection->create()->setEntityTypeFilter($this->_getCpCollectionInstance()->getEntity()->getTypeId())->load()->toOptionHash();
     $this->addColumn('set_name', ['header' => __('Attribute Set'), 'width' => '100px', 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets]);
     $this->addColumn('chooser_sku', ['header' => __('SKU'), 'name' => 'chooser_sku', 'width' => '80px', 'index' => 'sku']);
     $this->addColumn('chooser_name', ['header' => __('Product'), 'name' => 'chooser_name', 'index' => 'name']);
     return parent::_prepareColumns();
 }
示例#7
0
 /**
  * @return $this
  */
 protected function _initAttributeSets()
 {
     $attributeSetOne = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\Set')->disableOriginalConstructor()->getMock();
     $attributeSetOne->expects($this->any())->method('getAttributeSetName')->willReturn('attributeSet1');
     $attributeSetOne->expects($this->any())->method('getId')->willReturn('1');
     $attributeSetTwo = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\Set')->disableOriginalConstructor()->getMock();
     $attributeSetTwo->expects($this->any())->method('getAttributeSetName')->willReturn('attributeSet2');
     $attributeSetTwo->expects($this->any())->method('getId')->willReturn('2');
     $attributeSetCol = [$attributeSetOne, $attributeSetTwo];
     $collection = $this->getMockBuilder('\\Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection')->disableOriginalConstructor()->getMock();
     $collection->expects($this->once())->method('setEntityTypeFilter')->with(self::ENTITY_TYPE_ID)->willReturn($attributeSetCol);
     $this->_setColFactory->expects($this->once())->method('create')->willReturn($collection);
     return $this;
 }
示例#8
0
 /**
  * @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;
 }
示例#9
0
 /**
  * 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;
 }