Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. public function actionIncart(){
  2.  
  3.         $product = Catalog::model()->findByPk($_POST['id']);
  4.         $sizes = explode(',', $product->size);
  5.         $count = explode(',', $product->count);
  6.         $size_count = 0;
  7.  
  8.         if(isset($_POST['size'])){
  9.             foreach($sizes as $key=>$size){
  10.                 if($_POST['size'] == $size){
  11.                     $size_count = $count[$key];
  12.                 }
  13.             }
  14.             $product->chosenSize = $_POST['size'];
  15.             $position = Yii::app()->shoppingCart->itemAt($_POST['id'].'_'.$_POST['size']);
  16.             if($position){
  17.                 $count_cart = $position->getQuantity()+1;
  18.                 if($count_cart <= $size_count){
  19.                     Yii::app()->shoppingCart->put($product);
  20.                     echo Yii::app()->shoppingCart->getItemsCount();
  21.                 } else {
  22.                     echo false;
  23.                 }
  24.             } else {
  25.                 Yii::app()->shoppingCart->put($product);
  26.                 echo Yii::app()->shoppingCart->getItemsCount();
  27.             }
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement