Example #1
0
 function actionProductPriceSave()
 {
     $this->checkLogin();
     if (!empty($_POST)) {
         $product_code = Util::input($_POST['product_code']);
         $product_prices = str_replace(",", "", Util::input($_POST['product_price']));
         $product_price_sends = str_replace(",", "", Util::input($_POST['product_price_send']));
         $qtys = Util::input($_POST['qty']);
         $qty_ends = Util::input($_POST['qty_end']);
         $i = 0;
         ProductPrice::model()->deleteAllByAttributes(array("product_barcode" => $product_code));
         foreach ($product_prices as $product_price) {
             $price = $product_price;
             $price_send = $product_price_sends[$i];
             $qty = $qtys[$i];
             $qty_end = $qty_ends[$i];
             if ($qty > 0 && $price > 0) {
                 $productPrice = new ProductPrice();
                 $productPrice->product_barcode = $product_code;
                 $productPrice->price = $price;
                 $productPrice->price_send = $price_send;
                 $productPrice->qty = $qty;
                 $productPrice->qty_end = $qty_end;
                 $productPrice->order_field = $i + 1;
                 $productPrice->save();
             }
             $i++;
         }
         echo 'success';
     }
 }