} ?> <?php } ?> <tr> <th colspan="2"><?php echo Yii::t('app', 'Summary'); ?> </th> <th><?php echo $model->items_count; ?> </th> <th colspan="2"><?php echo Yii::$app->formatter->asDecimal(PriceHelper::getOrderPrice($model), 2); ?> </th> </tr> </tbody> </table> <div class="do-not-print"> <br /> <div class="row"> <div class="col-xs-6"> <label for="add-product"><?php echo Yii::t('app', 'Add a new product to order'); ?> </label> </div>
/** * Calculate order total price and items count with all additional markups. * @param bool $callSave Call save method after calculating. * @param bool $deleteNotActiveProducts Delete Order Item if product is not active or is not exist. * @return bool */ public function calculate($callSave = false, $deleteNotActiveProducts = true) { $itemsCount = 0; foreach ($this->items as $item) { if (null === OrderItem::findOne(['id' => $item->id])) { $item->delete(); continue; } if ($deleteNotActiveProducts && (null === $item->product || $item->product->active == 0)) { $item->delete(); continue; } if (Yii::$app->getModule('shop')->countChildrenProducts == 1) { $itemsCount += Yii::$app->getModule('shop')->countUniqueProductsOnly == 1 ? 1 : $item->quantity; } else { if ($item->parent_id == 0) { $itemsCount += Yii::$app->getModule('shop')->countUniqueProductsOnly == 1 ? 1 : $item->quantity; } } } $event = new OrderCalculateEvent(); $event->order = $this; $event->price = PriceHelper::getOrderPrice($this, SpecialPriceList::TYPE_CORE); EventTriggeringHelper::triggerSpecialEvent($event); $this->items_count = $itemsCount; $this->total_price = PriceHelper::getOrderPrice($this); $event->state = OrderCalculateEvent::AFTER_CALCULATE; EventTriggeringHelper::triggerSpecialEvent($event); TagDependency::invalidate(Yii::$app->cache, ['Session:' . Yii::$app->session->id]); return $callSave ? $this->save(true, ['items_count', 'total_price', 'total_price_with_shipping']) : true; }