Пример #1
0
 protected function insertRow($itemData)
 {
     $idParts = explode('_', $itemData['id']);
     $productId = (int) $idParts[0];
     $colorId = (int) $idParts[1];
     $sizeId = $idParts[2];
     $resultSet = (new Query())->select(['{{%product}}.`only_all_sizes`          AS `only_all_sizes`', '{{%product}}.`type`                 AS `product_type`', '{{%product}}.`manufacture`                 AS `manufacture`', '{{%product}}.`manufacture_sku`                 AS `manufacture_sku`', '{{%product_size}}.`id`                 AS `size_id`', '{{%product_size}}.`price`              AS `size_cost`', '{{%product_size}}.`qty`                AS `size_qty`', 'CONCAT("' . Yii::$app->homeUrl . '/catalog/", {{%product}}.slug, ".html") AS url', '{{%product_type_size}}.`name`          AS `size_name`', '{{%product_type_size}}.`id`            AS `size_order`'])->from('{{%product}}')->leftJoin('{{%product_size}}', '{{%product_size}}.product_id = {{%product}}.id')->leftJoin('{{%product_type_size}}', '{{%product_type_size}}.id = {{%product_size}}.type_size_id')->where('{{%product_size}}.product_id = :product_id', ['product_id' => $productId]);
     if ($colorId) {
         $resultSet = $resultSet->andWhere('{{%product_size}}.color_id = :colorId', ['colorId' => $colorId]);
     }
     if ($sizeId !== 'all') {
         $sizeId = (int) $sizeId;
         $resultSet = $resultSet->andWhere('{{%product_size}}.id = :sizeId', ['sizeId' => $sizeId]);
     }
     $resultSet = $resultSet->andWhere('{{%product_size}}.price != 0')->all();
     foreach ($resultSet as $row) {
         $itemRow = new CartItem();
         $itemRow->product_id = (int) $itemData['productId'];
         $itemRow->product_name = $itemData['productName'];
         $itemRow->product_image = $itemData['productImage'];
         $itemRow->manufacture = $row['manufacture'];
         $itemRow->manufacture_sku = $row['manufacture_sku'];
         $itemRow->product_url = $row['url'];
         $itemRow->product_type = $row['product_type'];
         $itemRow->qty = (int) $itemData['qty'];
         $itemRow->total = (int) $itemData['qty'] * (int) $row['size_cost'];
         $itemRow->color_id = $colorId;
         $itemRow->color_image = $itemData['colorImage'];
         $itemRow->color_name = '';
         $itemRow->size_id = $row['size_id'];
         //            $itemRow->size_name = $row['size_name'];
         $itemRow->size_name = $itemData['sizeName'];
         $itemRow->size_cost = (int) $row['size_cost'];
         $itemRow->only_all_sizes = (int) $row['only_all_sizes'];
         $itemRow->row_id = $itemData['rowId'];
         $itemRow->order_id = $itemData['orderId'];
         if (!$itemRow->save()) {
             Yii::error($itemRow->getErrors(), __LINE__);
         }
     }
 }