Beispiel #1
0
 public function testGetCompositeTypes()
 {
     $property = new \ReflectionProperty($this->_model, '_compositeTypes');
     $property->setAccessible(true);
     $this->assertNull($property->getValue($this->_model));
     $this->assertEquals(['type_id_3'], $this->_model->getCompositeTypes());
 }
 /**
  * Retrieve list of children ids for a product list.
  *
  * Warning the result use children ids as a key and list of parents as value
  *
  * @param array $productIds List of parent product ids.
  *
  * @return array
  */
 public function loadChildrens($productIds)
 {
     $children = [];
     foreach ($this->catalogProductType->getCompositeTypes() as $productTypeId) {
         $typeInstance = $this->getProductTypeInstance($productTypeId);
         $relation = $typeInstance->getRelationInfo();
         if ($relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) {
             $relationTable = $this->getTable($relation->getTable());
             $parentFieldName = $relation->getParentFieldName();
             $childFieldName = $relation->getChildFieldName();
             $select = $this->getConnection()->select()->from(['main' => $relationTable], [$parentFieldName, $childFieldName])->where("main.{$parentFieldName} in (?)", $productIds);
             if ($relation->getWhere() !== null) {
                 $select->where($relation->getWhere());
             }
             $configurationTable = $this->getTable("catalog_product_super_attribute");
             $configurableAttrExpr = "GROUP_CONCAT(DISTINCT super_table.attribute_id SEPARATOR ',')";
             $select->joinLeft(["super_table" => $configurationTable], "super_table.product_id = main.{$parentFieldName}", ["configurable_attributes" => new \Zend_Db_Expr($configurableAttrExpr)]);
             $select->group("main.{$childFieldName}");
             $data = $this->getConnection()->fetchAll($select);
             foreach ($data as $relationRow) {
                 $parentId = (int) $relationRow[$parentFieldName];
                 $childId = (int) $relationRow[$childFieldName];
                 $configurableAttributes = array_filter(explode(',', $relationRow["configurable_attributes"]));
                 $children[$childId][] = ["parent_id" => $parentId, "configurable_attributes" => $configurableAttributes];
             }
         }
     }
     return $children;
 }
Beispiel #3
0
 /**
  * Add ordered qty's
  *
  * @param string $from
  * @param string $to
  * @return $this
  */
 public function addOrderedQty($from = '', $to = '')
 {
     $adapter = $this->getConnection();
     $compositeTypeIds = $this->_productType->getCompositeTypes();
     $orderTableAliasName = $adapter->quoteIdentifier('order');
     $orderJoinCondition = array($orderTableAliasName . '.entity_id = order_items.order_id', $adapter->quoteInto("{$orderTableAliasName}.state <> ?", \Magento\Sales\Model\Order::STATE_CANCELED));
     $productJoinCondition = array($adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds), 'e.entity_id = order_items.product_id', $adapter->quoteInto('e.entity_type_id = ?', $this->getProductEntityTypeId()));
     if ($from != '' && $to != '') {
         $fieldName = $orderTableAliasName . '.created_at';
         $orderJoinCondition[] = $this->_prepareBetweenSql($fieldName, $from, $to);
     }
     $this->getSelect()->reset()->from(array('order_items' => $this->getTable('sales_flat_order_item')), array('ordered_qty' => 'SUM(order_items.qty_ordered)', 'order_items_name' => 'order_items.name'))->joinInner(array('order' => $this->getTable('sales_flat_order')), implode(' AND ', $orderJoinCondition), array())->joinLeft(array('e' => $this->getProductEntityTableName()), implode(' AND ', $productJoinCondition), array('entity_id' => 'order_items.product_id', 'entity_type_id' => 'e.entity_type_id', 'attribute_set_id' => 'e.attribute_set_id', 'type_id' => 'e.type_id', 'sku' => 'e.sku', 'has_options' => 'e.has_options', 'required_options' => 'e.required_options', 'created_at' => 'e.created_at', 'updated_at' => 'e.updated_at'))->where('parent_item_id IS NULL')->group('order_items.product_id')->having('SUM(order_items.qty_ordered) > ?', 0);
     return $this;
 }
 public function testGetCompositeTypes()
 {
     $types = $this->_productType->getCompositeTypes();
     $this->assertInternalType('array', $types);
     $this->assertContains(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE, $types);
 }
 /**
  * {@inheritdoc}
  */
 public function getCompositeTypes()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getCompositeTypes');
     if (!$pluginInfo) {
         return parent::getCompositeTypes();
     } else {
         return $this->___callPlugins('getCompositeTypes', func_get_args(), $pluginInfo);
     }
 }