Пример #1
0
 public function afterGetSearchableAttributes(\Magento\CatalogSearch\Block\Advanced\Form $subject, $result)
 {
     $storeAttributes = $result;
     $table = $this->_resourceModel->getTable('genmato_multistoresearchfields_attribute_search_store');
     $tableAlias = 'attribute_search_store';
     $storeId = $this->_storeManager->getStore()->getId();
     $storeAttributes->getSelect()->joinLeft([$tableAlias => $table], "main_table.attribute_id={$tableAlias}.attribute_id", [])->where("({$tableAlias}.store_id='0' OR {$tableAlias}.store_id='{$storeId}')");
     $attrIds = $storeAttributes->getAllIds();
     foreach ($result as $item) {
         if (!in_array($item->getId(), $attrIds)) {
             $result->removeItemByKey($item->getId());
         }
     }
     return $result;
 }
 public function afterSave(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject, $attribute)
 {
     $oldStores = $this->advSearchStores->getStoreIds($attribute->getId());
     $newStores = (array) $attribute->getAdvancedSearchStoreIds();
     // If no stores are selected or all stores and stores are selected set only to all stores value
     if (empty($newStores) || count($newStores) > 1 && in_array(0, $newStores)) {
         $newStores = [0];
     }
     $insert = array_diff($newStores, $oldStores);
     $delete = array_diff($oldStores, $newStores);
     if ($delete) {
         $this->advSearchStores->deleteStoreIds($attribute->getId(), $delete);
     }
     if ($insert) {
         $this->advSearchStores->saveStoreIds($attribute->getId(), $insert);
     }
 }