Advertisement
dimti

Untitled

Feb 1st, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Class AjaxBasketAddAction
  5.  * @property int $product_id
  6.  */
  7. class AjaxBasketChangeCountAction extends \Majestic\App\AjaxAction {
  8.     /**
  9.      * @var OrderModel
  10.      */
  11.     private $order_model;
  12.  
  13.     /**
  14.      * @var ProductModel
  15.      */
  16.     private $product_model;
  17.  
  18.     var $product_id;
  19.  
  20.     var $stock_id;
  21.  
  22.     public function __construct()
  23.     {
  24.         $this->order_model   = new OrderModel();
  25.  
  26.         $this->product_model = new ProductModel();
  27.  
  28.         parent::__construct();
  29.     }
  30.  
  31.     public function execute()
  32.     {
  33.         if ( !( $product = $this->product_model->get( $this->product_id ) ) ) {
  34.             $message = 'Product not found. Id ' . $this->product_id;
  35.  
  36.             App::abort( 404, $message );
  37.         }
  38.  
  39.         switch ( \Majestic\Env::getParam( 'method' ) ) {
  40.             case 'increase':
  41.                 $this->order_model->increaseProductCount( $this->product_id, $this->stock_id );
  42.  
  43.                 break;
  44.  
  45.             case 'decrease':
  46.                 $this->order_model->decreaseProductCount( $this->product_id, $this->stock_id );
  47.  
  48.                 break;
  49.         }
  50.  
  51.         if ( !\Majestic\Env::Post( 'is_ajax' ) ) {
  52.             $this->redirect( '/order/basket' );
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement