Exemple #1
0
 public function actionSaveProductPriceBarCode()
 {
     $this->checkLogin();
     if (!empty($_POST)) {
         $barcodes = Util::input($_POST['barcode']);
         $price_befores = Util::input($_POST['price_before']);
         $prices = Util::input($_POST['price']);
         $qtys = Util::input($_POST['qty']);
         $names = Util::input($_POST['name']);
         $barcode_fk = Util::input($_POST['product_code']);
         if (!empty($barcodes)) {
             $size = count($barcodes);
             // delete
             BarcodePrice::model()->deleteAllByAttributes(array('barcode_fk' => $barcode_fk));
             // insert
             for ($i = 0; $i < $size; $i++) {
                 if ($prices[$i] != 0) {
                     $barcodePrice = new BarcodePrice();
                     $barcodePrice->barcode = $barcodes[$i];
                     $barcodePrice->price_before = $price_befores[$i];
                     $barcodePrice->price = $prices[$i];
                     $barcodePrice->qty_sub_stock = $qtys[$i];
                     $barcodePrice->name = $names[$i];
                     $barcodePrice->barcode_fk = $barcode_fk;
                     $barcodePrice->save();
                 }
             }
             echo 'success';
         }
     }
 }