?> <?php foreach ($dataProvider->query->all() as $order) { ?> <?php if ($order->products) { foreach ($order->products as $productData) { $v3toysId = \yii\helpers\ArrayHelper::getValue($productData, 'v3toys_product_id'); $id = \yii\helpers\ArrayHelper::getValue($productData, 'product_id'); $quantity = \yii\helpers\ArrayHelper::getValue($productData, 'quantity'); $price = \yii\helpers\ArrayHelper::getValue($productData, 'price'); /** * @var $element \skeeks\cms\shop\models\ShopCmsContentElement */ if ($element = \skeeks\cms\shop\models\ShopCmsContentElement::findOne((int) $id)) { $purchasingPrice = $purchasingPrice + $quantity * (double) $element->shopProduct->purchasing_price; } else { $notFoundProducts++; } } } ?> <?php $moneyPurchasing = \Yii::$app->money->newMoney((string) $purchasingPrice); $moneyTotal = $moneyTotal->add($order->money); $moneyTotalNoDelivery = $moneyTotalNoDelivery->add($order->moneyOriginal); ?> <?php }
/** * @param $cmsElementId * @param int $quantity * * @return $this * @throws Exception */ public function addProduct($cmsElementId, $quantity = 1) { /** * @var $shopElement ShopCmsContentElement */ $shopElement = ShopCmsContentElement::findOne($cmsElementId); if (!$shopElement) { throw new Exception('Этот продукт не найден'); } $products = []; $products[] = ['v3toys_product_id' => (int) $shopElement->relatedPropertiesModel->getAttribute(\Yii::$app->v3toysSettings->v3toysIdPropertyName), 'price' => $shopElement->shopProduct->baseProductPriceValue, 'quantity' => $quantity, 'name' => (string) $shopElement->name, 'product_id' => (int) $shopElement->id]; $this->products = ArrayHelper::merge((array) $this->products, $products); return $this; }