示例#1
0
 /**
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $result
  * @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
  */
 public function afterSave(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject, \Magento\Catalog\Model\ResourceModel\Eav\Attribute $result)
 {
     if ($this->swatchHelper->isSwatchAttribute($subject)) {
         $this->typeList->invalidate(Block::TYPE_IDENTIFIER);
         $this->typeList->invalidate(Collection::TYPE_IDENTIFIER);
     }
     return $result;
 }
 /**
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @param \Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject
  * @param \Closure $proceed
  * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter
  * @return mixed
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function aroundRender(\Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject, \Closure $proceed, \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter)
 {
     if ($filter->hasAttributeModel()) {
         if ($this->swatchHelper->isSwatchAttribute($filter->getAttributeModel())) {
             return $this->layout->createBlock($this->block)->setSwatchFilter($filter)->toHtml();
         }
     }
     return $proceed($filter);
 }
 /**
  * Retrieve list of attributes
  *
  * @param array $ids
  * @return array
  */
 public function getAttributes($ids)
 {
     $collection = $this->collectionFactory->create();
     $collection->addFieldToFilter('main_table.attribute_id', $ids);
     $attributes = [];
     foreach ($collection->getItems() as $attribute) {
         $attributes[] = ['id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false), 'canCreateOption' => !$this->dataHelper->isSwatchAttribute($attribute)];
     }
     return $attributes;
 }
示例#4
0
 /**
  * {@inheritDoc}
  */
 protected function canRenderFilter()
 {
     $canRenderFilter = false;
     try {
         $attribute = $this->getFilter()->getAttributeModel();
         $canRenderFilter = $this->swatchHelper->isSwatchAttribute($attribute);
     } catch (\Exception $e) {
     }
     return $canRenderFilter;
 }
 /**
  * Check if we can replace original image with swatch image on catalog/category/list page
  *
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return bool
  */
 protected function canReplaceImageWithSwatch($attribute)
 {
     $result = true;
     if (!$this->swatchHelperData->isSwatchAttribute($attribute)) {
         $result = false;
     }
     if (!$attribute->getUsedInProductListing() || !$attribute->getIsFilterable() || !$attribute->getData('update_product_preview_image')) {
         $result = false;
     }
     return $result;
 }
示例#6
0
 /**
  * @dataProvider dataIsSwatchAttribute
  */
 public function testIsSwatchAttribute($times, $swatchType, $boolResult)
 {
     $this->attributeMock->method('hasData')->with('swatch_input_type')->willReturn(true);
     $this->attributeMock->expects($this->exactly($times))->method('getData')->with('swatch_input_type')->willReturn($swatchType);
     $result = $this->swatchHelperObject->isSwatchAttribute($this->attributeMock);
     if ($boolResult) {
         $this->assertTrue($result);
     } else {
         $this->assertFalse($result);
     }
 }
示例#7
0
 /**
  * Save default swatch value using Swatch model instead of Eav model
  *
  * @param Attribute $attribute
  * @return void
  */
 protected function saveDefaultSwatchOptionValue(Attribute $attribute)
 {
     if (!$this->swatchHelper->isSwatchAttribute($attribute)) {
         return;
     }
     $defaultValue = $attribute->getData('default/0');
     if (!empty($defaultValue)) {
         /** @var \Magento\Swatches\Model\Swatch $swatch */
         $swatch = $this->swatchFactory->create();
         if (substr($defaultValue, 0, 6) == self::BASE_OPTION_TITLE) {
             $defaultValue = $this->dependencyArray[$defaultValue];
         }
         $swatch->getResource()->saveDefaultSwatchOption($attribute->getId(), $defaultValue);
     }
 }