Ejemplo n.º 1
0
 protected function fillPriceList($list_id)
 {
     $listino = Listini::findFirst($list_id);
     if ($listino) {
         $versione = $listino->getLastVersionModel();
         $prodotti = Product::find();
         foreach ($prodotti as $prodotto) {
             $info = new InfoProdotti();
             $info->ps_product_id = $prodotto->id_product;
             $info->pr_listini_versioni_id = $versione->id;
             if ($info->save()) {
                 $prezzi = new PrezziProdotti();
                 $prezzi->pr_info_prodotti_id = $info->id;
                 $prezzi->pr_listini_versioni_id = $versione->id;
                 $prezzi->save();
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function addPriceListAction()
 {
     if ($this->request->isPost()) {
         if ($this->token->check()) {
             $name = (string) $this->request->getPost('listName');
             $empty = $this->request->getPost('listEmpty') == 'on' ? true : false;
             $listino = new PriceLists();
             $listino->name = $name;
             $check = false;
             try {
                 if ($listino->save() == false) {
                     foreach ($listino->getMessages() as $message) {
                         $this->flash->error($message);
                     }
                 } else {
                     $check = true;
                     $this->flash->success(_('Nuovo Listino creato'));
                 }
             } catch (\Exception $e) {
                 $this->flash->error($e->getMessage());
             }
             $idClone = (int) $this->request->getPost('listClone');
             if ($check && $idClone > 0) {
                 return $this->clonePriceList($idClone, $listino->id);
             }
             if ($check && !$empty) {
                 $prodotti = Product::find();
                 foreach ($prodotti as $prodotto) {
                     $prezzi = new ProductPrices();
                     $prezzi->product_id = $prodotto->id_product;
                     $prezzi->price_lists_id = $listino->id;
                     if ($prezzi->save() == false) {
                         foreach ($prezzi->getMessages() as $message) {
                             $this->flash->error($message);
                         }
                     }
                 }
             }
             return $this->forward('products', 'priceListsAll');
         }
     }
 }