protected function proceed()
 {
     switch ($this->action) {
         case 'get':
             if (isset($this->params['id'])) {
                 $this->succeed(ProductsService::get($this->params['id']));
             } else {
                 if (isset($this->params['reference'])) {
                     $this->succeed(ProductsService::getByRef($this->params['reference']));
                 } else {
                     $this->succeed(ProductsService::getByCode($this->params['code']));
                 }
             }
             break;
         case 'getAll':
             if (isset($this->params['all']) && in_array($this->params['all'], array(true, 1))) {
                 $this->succeed(ProductsService::getAll(true));
             } else {
                 $this->succeed(ProductsService::getAll());
             }
             break;
         case 'getCategory':
             $this->succeed(ProductsService::getByCategory($this->params['id']));
             break;
     }
 }
Exemple #2
0
 /** Add 0 quantities to all on sales and missing products in inventory */
 public function fillZero()
 {
     $prds = ProductsService::getAll(false);
     foreach ($this->items as $item) {
         foreach ($prds as $i => $prd) {
             if ($prd->id == $item->productId) {
                 array_splice($prds, $i, 1);
                 break;
             }
         }
     }
     // Registered products removed, add 0 items
     foreach ($prds as $prd) {
         $this->addItem(new InventoryItem($this->id, $prd->id, null, 0, 0, 0, null, null));
     }
 }
 public function listAction()
 {
     return ProductsService::getAll();
 }