/**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($product = $this->product) {
         $this->sum = $product->price * $this->quantity;
     }
 }
Exemple #2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $app = Application::$app;
     $cartName = static::shortClass();
     if ($cart = $app::$cookies->{$cartName}) {
         $cart = json_decode($cart, true);
         foreach ($this->asArray() as $name => $value) {
             $this->{$name} = $cart[$name];
         }
         if (isset($cart['products'])) {
             foreach ($cart['products'] as $product) {
                 $this->products[] = CartProductModel::model($product);
             }
         }
     }
 }