Exemple #1
0
 public function editProductFormSubmitted(Form $form)
 {
     $values = $form->getValues();
     $product = $this->productFactory->createProduct();
     $product->loadById((int) $values['product_id']);
     $product->setTitle($values->title);
     $product->setSku($values->sku);
     $product->setPrice($values->price);
     $product->setActive($values->active);
     $product->setCategoryId($values->category);
     $product->setBrandId($values->brand);
     $warehouses = $this->warehouseManager->getAll();
     foreach ($warehouses as $warehouse) {
         $warehouse_id = $warehouse['id'];
         $id = 'warehouse_' . $warehouse_id;
         $total = (int) $values[$id];
         if ($total !== 0) {
             if ($product->getWarehouses()->getWarehouseTotal($warehouse_id) > 0) {
                 $product->getWarehouses()->updateWarehouse($warehouse_id, $total);
             } else {
                 $product->getWarehouses()->addWarehouse($warehouse_id, $total);
             }
         } else {
             if ($product->getWarehouses()->getWarehouseTotal($warehouse_id) > 0) {
                 $product->getWarehouses()->deleteWarehouse($warehouse_id);
             }
         }
     }
     $product->save();
     $this->flashMessage("Product has been successfully updated.", "success");
     $this->redirect("this");
 }
Exemple #2
0
 public function actionDelete($id)
 {
     $this->warehouseManager->delete($id);
     $this->flashMessage('Warehouse has been successfully deleted.', 'success');
     $this->redirect('default');
 }