public function load($cart, $formName = null) { if (!empty($cart)) { foreach ($cart as $priceId => $count) { $price = ProductPrice::findOne($priceId); if (!empty($price)) { $cartItem = new CartItem(); $cartItem->price = $price; $cartItem->count = $count; $this->items[] = $cartItem; $this->sum += $price->currencySalePrice * $count; } } } return true; }
/** * Users which have 'updateOwnProduct' permission can delete price only from Product models that have been created by their. * Users which have 'updateProduct' permission can delete price from all Product models. * * @param integer $priceId * @param integer $id * @param integer $languageId * @return mixed * @throws ForbiddenHttpException */ public function actionRemovePrice($priceId, $id, $languageId) { if (\Yii::$app->user->can('updateProduct', ['productOwner' => Product::findOne($id)->owner])) { ProductPrice::deleteAll(['id' => $priceId]); return $this->actionAddPrice($id, $languageId); } else { throw new ForbiddenHttpException(\Yii::t('shop', 'You have not permission to do this action.')); } }
/** * @return \yii\db\ActiveQuery */ public function getPrices() { return $this->hasMany(ProductPrice::className(), ['sale_type_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getPrice() { return $this->hasOne(ProductPrice::className(), ['id' => 'price_id']); }