Example #1
0
 /**
  * Get products by IDs
  * @param array    $productIds
  * @param null|int $chunkSize
  * @param bool     $filterVisibility
  * @return \Magento\Catalog\Model\Resource\Product\Collection
  */
 public function getProducts(array $productIds = [], $chunkSize = null, $filterVisibility = true)
 {
     $this->_productCollection->addAttributeToSelect('sku')->addAttributeToSelect($this->_config->getProductAttributes())->addAttributeToSelect('status')->addAttributeToSelect('visibility');
     if ($filterVisibility) {
         $this->_productCollection->addAttributeToFilter('visibility', ['in' => [Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH]])->addAttributeToFilter('status', Status::STATUS_ENABLED);
     }
     if (!empty($productIds)) {
         $this->_productCollection->addIdFilter($productIds);
     }
     if ($chunkSize !== null) {
         $this->_productCollection->setPageSize($chunkSize);
     }
     return $this->_productCollection;
 }
Example #2
0
 /**
  * Prepare configurable data for export
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @param int $productIds
  * @return void
  */
 public function prepareData($collection, $productIds)
 {
     $collection->addAttributeToFilter('entity_id', ['in' => $productIds])->addAttributeToFilter('type_id', ['eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE]);
     while ($product = $collection->fetchItem()) {
         $productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);
         foreach ($productAttributesOptions as $productAttributeOption) {
             $this->configurableData[$product->getId()] = [];
             $variations = [];
             $variationsPrices = [];
             $variationsLabels = [];
             foreach ($productAttributeOption as $optValues) {
                 $variations[$optValues['sku']][] = $optValues['attribute_code'] . '=' . $optValues['option_title'];
                 $priceType = $optValues['pricing_is_percent'] ? 'percent' : 'fixed';
                 $variationsPrices[] = 'name=' . $optValues['attribute_code'] . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'value=' . $optValues['option_title'] . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'price=' . $optValues['pricing_value'] . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'price_type=' . $priceType;
                 if (!empty($optValues['super_attribute_label'])) {
                     $variationsLabels[$optValues['attribute_code']] = $optValues['attribute_code'] . '=' . $optValues['super_attribute_label'];
                 }
             }
             foreach ($variations as $sku => $values) {
                 $variations[$sku] = 'sku=' . $sku . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $values);
             }
             $variations = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations);
             $variationsPrices = array_unique($variationsPrices);
             $variationsPrices = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variationsPrices);
             $variationsLabels = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $variationsLabels);
             $this->configurableData[$product->getId()] = ['configurable_variations' => $variations, 'configurable_variation_prices' => $variationsPrices, 'configurable_variation_labels' => $variationsLabels];
         }
     }
 }
Example #3
0
 /**
  * Prepare configurable data for export
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @param int $productIds
  * @return void
  */
 public function prepareData($collection, $productIds)
 {
     $collection->addAttributeToFilter('entity_id', array('in' => $productIds))->addAttributeToFilter('type_id', array('eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE));
     while ($product = $collection->fetchItem()) {
         $productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);
         foreach ($productAttributesOptions as $productAttributeOption) {
             $this->configurableData[$product->getId()] = array();
             foreach ($productAttributeOption as $optionValues) {
                 $priceType = $optionValues['pricing_is_percent'] ? '%' : '';
                 $this->configurableData[$product->getId()][] = array('_super_products_sku' => $optionValues['sku'], '_super_attribute_code' => $optionValues['attribute_code'], '_super_attribute_option' => $optionValues['option_title'], '_super_attribute_price_corr' => $optionValues['pricing_value'] . $priceType);
             }
         }
     }
 }
Example #4
0
 /**
  * Add attribute to filter
  *
  * @param AbstractAttribute|string $attribute
  * @param array|null $condition
  * @param string $joinType
  * @return $this
  */
 public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner')
 {
     switch ($attribute) {
         case 'rt.review_id':
         case 'rt.created_at':
         case 'rt.status_id':
         case 'rdt.title':
         case 'rdt.nickname':
         case 'rdt.detail':
             $conditionSql = $this->_getConditionSql($attribute, $condition);
             $this->getSelect()->where($conditionSql);
             break;
         case 'stores':
             $this->setStoreFilter($condition);
             break;
         case 'type':
             if ($condition == 1) {
                 $conditionParts = array($this->_getConditionSql('rdt.customer_id', array('is' => new \Zend_Db_Expr('NULL'))), $this->_getConditionSql('rdt.store_id', array('eq' => \Magento\Store\Model\Store::DEFAULT_STORE_ID)));
                 $conditionSql = implode(' AND ', $conditionParts);
             } elseif ($condition == 2) {
                 $conditionSql = $this->_getConditionSql('rdt.customer_id', array('gt' => 0));
             } else {
                 $conditionParts = array($this->_getConditionSql('rdt.customer_id', array('is' => new \Zend_Db_Expr('NULL'))), $this->_getConditionSql('rdt.store_id', array('neq' => \Magento\Store\Model\Store::DEFAULT_STORE_ID)));
                 $conditionSql = implode(' AND ', $conditionParts);
             }
             $this->getSelect()->where($conditionSql);
             break;
         default:
             parent::addAttributeToFilter($attribute, $condition, $joinType);
             break;
     }
     return $this;
 }