Пример #1
0
 /**
  * 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();
 }
Пример #2
0
 /**
  * Retrieve list of attributes with admin store label containing $labelPart
  *
  * @param string $labelPart
  * @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getSuggestedAttributes($labelPart)
 {
     $escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->configurableAttributeHandler->getApplicableAttributes()->addFieldToFilter('frontend_label', ['like' => $escapedLabelPart]);
     $result = [];
     foreach ($collection->getItems() as $id => $attribute) {
         /** @var $attribute \Magento\Catalog\Model\Resource\Eav\Attribute */
         if ($this->configurableAttributeHandler->isAttributeApplicable($attribute)) {
             $result[$id] = ['id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false)];
         }
     }
     return $result;
 }
Пример #3
0
 /**
  * Prepare data index for indexable select attributes
  *
  * @param array $entityIds the entity ids limitation
  * @param int $attributeId the attribute id limitation
  * @return $this
  */
 protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
 {
     $adapter = $this->_getWriteAdapter();
     $idxTable = $this->getIdxTable();
     // prepare select attributes
     if (is_null($attributeId)) {
         $attrIds = $this->_getIndexableAttributes(false);
     } else {
         $attrIds = array($attributeId);
     }
     if (!$attrIds) {
         return $this;
     }
     /**@var $subSelect \Magento\Framework\DB\Select*/
     $subSelect = $adapter->select()->from(array('s' => $this->getTable('store')), array('store_id', 'website_id'))->joinLeft(array('d' => $this->getTable('catalog_product_entity_int')), '1 = 1 AND (d.store_id = 0 OR d.store_id = s.store_id)', array('entity_id', 'attribute_id', 'value'))->joinLeft(array('d2' => $this->getTable('catalog_product_entity_int')), sprintf('d.entity_id = d2.entity_id AND d2.attribute_id = %s AND d2.value = %s AND d.store_id = d2.store_id', $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'status')->getId(), ProductStatus::STATUS_ENABLED), array())->where('s.store_id != 0')->where('d.value IS NOT NULL')->where('d2.value IS NOT NULL')->group(array('s.store_id', 's.website_id', 'd.entity_id', 'd.attribute_id', 'd.value'));
     if (!is_null($entityIds)) {
         $subSelect->where('d.entity_id IN(?)', $entityIds);
     }
     /**@var $select \Magento\Framework\DB\Select*/
     $select = $adapter->select()->distinct(true)->from(array('pid' => new \Zend_Db_Expr(sprintf('(%s)', $subSelect->assemble()))), array())->joinLeft(array('pis' => $this->getTable('catalog_product_entity_int')), 'pis.entity_id = pid.entity_id AND pis.attribute_id = pid.attribute_id AND pis.store_id = pid.store_id', array())->columns(array('pid.entity_id', 'pid.attribute_id', 'pid.store_id', 'value' => $adapter->getIfNullSql('pis.value', 'pid.value')))->where('pid.attribute_id IN(?)', $attrIds);
     $select->where($this->_resourceHelper->getIsNullNotNullCondition('pis.value', 'pid.value'));
     /**
      * Exclude attribute values that contains NULL
      */
     $select->where('NOT(pis.value IS NULL AND pis.value_id IS NOT NULL)');
     /**
      * Add additional external limitation
      */
     $this->_eventManager->dispatch('prepare_catalog_product_index_select', array('select' => $select, 'entity_field' => new \Zend_Db_Expr('pid.entity_id'), 'website_field' => new \Zend_Db_Expr('pid.website_id'), 'store_field' => new \Zend_Db_Expr('pid.store_id')));
     $query = $select->insertFromSelect($idxTable);
     $adapter->query($query);
     return $this;
 }
Пример #4
0
 /**
  * Retrieve list of attributes with admin store label containing $labelPart
  *
  * @param string $labelPart
  * @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getSuggestedAttributes($labelPart)
 {
     $escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, array('position' => 'any'));
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->_attributeColFactory->create();
     $collection->addFieldToFilter('frontend_input', 'select')->addFieldToFilter('frontend_label', array('like' => $escapedLabelPart))->addFieldToFilter('is_configurable', array(array("eq" => 1), array('null' => true)))->addFieldToFilter('is_user_defined', 1)->addFieldToFilter('is_global', \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL);
     $result = array();
     $types = array(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL, \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE);
     foreach ($collection->getItems() as $id => $attribute) {
         /** @var $attribute \Magento\Catalog\Model\Resource\Eav\Attribute */
         if (!$attribute->getApplyTo() || count(array_diff($types, $attribute->getApplyTo())) === 0) {
             $result[$id] = array('id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false));
         }
     }
     return $result;
 }
Пример #5
0
 /**
  * Retrieve list of attributes with admin store label containing $labelPart
  *
  * @param string $labelPart
  * @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getSuggestedAttributes($labelPart)
 {
     $escapedLabelPart = $this->resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
     $availableFrontendTypes = $this->getAvailableFrontendTypes();
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->attributeCollectionFactory->create();
     $collection->addFieldToFilter('main_table.frontend_input', ['in' => $availableFrontendTypes->getData('values')])->addFieldToFilter('frontend_label', ['like' => $escapedLabelPart])->addFieldToFilter('is_user_defined', 1)->addFieldToFilter('is_global', \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL);
     $result = [];
     $types = [\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL, \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE];
     foreach ($collection->getItems() as $id => $attribute) {
         /** @var $attribute \Magento\Catalog\Model\Resource\Eav\Attribute */
         if (!$attribute->getApplyTo() || count(array_diff($types, $attribute->getApplyTo())) === 0) {
             $result[$id] = ['id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false)];
         }
     }
     return $result;
 }
Пример #6
0
 /**
  * Return array of static columns
  *
  * @return array
  */
 protected function getStaticColumns()
 {
     $columns = array();
     $columnsToSkip = array('entity_type_id', 'attribute_set_id');
     $describe = $this->getReadAdapter()->describeTable($this->getReadAdapter()->getTableName($this->getTableName('catalog_category_entity')));
     foreach ($describe as $column) {
         if (in_array($column['COLUMN_NAME'], $columnsToSkip)) {
             continue;
         }
         $isUnsigned = '';
         $options = null;
         $ddlType = $this->resourceHelper->getDdlTypeByColumnType($column['DATA_TYPE']);
         $column['DEFAULT'] = trim($column['DEFAULT'], "' ");
         switch ($ddlType) {
             case \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT:
             case \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER:
             case \Magento\Framework\DB\Ddl\Table::TYPE_BIGINT:
                 $isUnsigned = (bool) $column['UNSIGNED'];
                 if ($column['DEFAULT'] === '') {
                     $column['DEFAULT'] = null;
                 }
                 $options = null;
                 if ($column['SCALE'] > 0) {
                     $ddlType = \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL;
                 } else {
                     break;
                 }
                 // fall-through intentional
             // fall-through intentional
             case \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL:
                 $options = $column['PRECISION'] . ',' . $column['SCALE'];
                 $isUnsigned = null;
                 if ($column['DEFAULT'] === '') {
                     $column['DEFAULT'] = null;
                 }
                 break;
             case \Magento\Framework\DB\Ddl\Table::TYPE_TEXT:
                 $options = $column['LENGTH'];
                 $isUnsigned = null;
                 break;
             case \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP:
                 $options = null;
                 $isUnsigned = null;
                 break;
             case \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME:
                 $isUnsigned = null;
                 break;
         }
         $columns[$column['COLUMN_NAME']] = array('type' => array($ddlType, $options), 'unsigned' => $isUnsigned, 'nullable' => $column['NULLABLE'], 'default' => $column['DEFAULT'] === null ? false : $column['DEFAULT'], 'comment' => $column['COLUMN_NAME']);
     }
     $columns['store_id'] = array('type' => array(\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, 5), 'unsigned' => true, 'nullable' => false, 'default' => '0', 'comment' => 'Store Id');
     return $columns;
 }
Пример #7
0
 /**
  * Join Product Price Table with left-join possibility
  *
  * @see \Magento\Catalog\Model\Resource\Product\Collection::_productLimitationJoinPrice()
  * @param bool $joinLeft
  * @return $this
  */
 protected function _productLimitationPrice($joinLeft = false)
 {
     $filters = $this->_productLimitationFilters;
     if (empty($filters['use_price_index'])) {
         return $this;
     }
     $connection = $this->getConnection();
     $select = $this->getSelect();
     $joinCond = join(' AND ', array('price_index.entity_id = e.entity_id', $connection->quoteInto('price_index.website_id = ?', $filters['website_id']), $connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id'])));
     $fromPart = $select->getPart(\Zend_Db_Select::FROM);
     if (!isset($fromPart['price_index'])) {
         $least = $connection->getLeastSql(array('price_index.min_price', 'price_index.tier_price'));
         $minimalExpr = $connection->getCheckSql('price_index.tier_price IS NOT NULL', $least, 'price_index.min_price');
         $colls = array('price', 'tax_class_id', 'final_price', 'minimal_price' => $minimalExpr, 'min_price', 'max_price', 'tier_price');
         $tableName = array('price_index' => $this->getTable('catalog_product_index_price'));
         if ($joinLeft) {
             $select->joinLeft($tableName, $joinCond, $colls);
         } else {
             $select->join($tableName, $joinCond, $colls);
         }
         // Set additional field filters
         foreach ($this->_priceDataFieldFilters as $filterData) {
             $select->where(call_user_func_array('sprintf', $filterData));
         }
     } else {
         $fromPart['price_index']['joinCondition'] = $joinCond;
         $select->setPart(\Zend_Db_Select::FROM, $fromPart);
     }
     //Clean duplicated fields
     $this->_resourceHelper->prepareColumnsList($select);
     return $this;
 }