/**
  * Return array of static columns
  *
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function getStaticColumns()
 {
     $columns = [];
     $columnsToSkip = ['entity_type_id', 'attribute_set_id'];
     $describe = $this->connection->describeTable($this->connection->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']] = ['type' => [$ddlType, $options], 'unsigned' => $isUnsigned, 'nullable' => $column['NULLABLE'], 'default' => $column['DEFAULT'] === null ? false : $column['DEFAULT'], 'comment' => $column['COLUMN_NAME']];
     }
     $columns['store_id'] = ['type' => [\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, 5], 'unsigned' => true, 'nullable' => false, 'default' => '0', 'comment' => 'Store Id'];
     return $columns;
 }
 /**
  * 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();
 }
 /**
  * Retrieve list of attributes with admin store label containing $labelPart
  *
  * @param string $labelPart
  * @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
  */
 public function getSuggestedAttributes($labelPart)
 {
     $escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
     /** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection */
     $collection = $this->configurableAttributeHandler->getApplicableAttributes()->addFieldToFilter('frontend_label', ['like' => $escapedLabelPart]);
     $result = [];
     foreach ($collection->getItems() as $id => $attribute) {
         /** @var $attribute \Magento\Catalog\Model\ResourceModel\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;
 }
Beispiel #4
0
 /**
  * Join Product Price Table with left-join possibility
  *
  * @see \Magento\Catalog\Model\ResourceModel\Product\Collection::_productLimitationJoinPrice()
  * @param bool $joinLeft
  * @return $this
  */
 protected function _productLimitationPrice($joinLeft = false)
 {
     $filters = $this->_productLimitationFilters;
     if (!$filters->isUsingPriceIndex()) {
         return $this;
     }
     // Preventing overriding price loaded from EAV because we want to use the one from index
     $this->removeAttributeToSelect('price');
     $connection = $this->getConnection();
     $select = $this->getSelect();
     $joinCond = join(' AND ', ['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(\Magento\Framework\DB\Select::FROM);
     if (!isset($fromPart['price_index'])) {
         $least = $connection->getLeastSql(['price_index.min_price', 'price_index.tier_price']);
         $minimalExpr = $connection->getCheckSql('price_index.tier_price IS NOT NULL', $least, 'price_index.min_price');
         $colls = ['price', 'tax_class_id', 'final_price', 'minimal_price' => $minimalExpr, 'min_price', 'max_price', 'tier_price'];
         $tableName = ['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(\Magento\Framework\DB\Select::FROM, $fromPart);
     }
     //Clean duplicated fields
     $this->_resourceHelper->prepareColumnsList($select);
     return $this;
 }