Exemplo n.º 1
0
 private function checkInventoryLevels()
 {
     $errors = array();
     //check inventory levels
     $pdetailIds = array();
     $entries = $this->Ccart->getContents();
     foreach ($entries as $e) {
         if (!empty($e->uniques['pdetail'])) {
             array_push($pdetailIds, $e->uniques['pdetail']);
         }
     }
     if (count($pdetailIds) > 0) {
         $info = $this->Pdetail->find('all', array('conditions' => array('Pdetail.id IN (' . implode(',', $pdetailIds) . ')')));
         foreach ($entries as $e) {
             if ($e->getType() == 'product') {
                 //dont have enough product
                 $color = 'Unknown';
                 $size = 'Unknown';
                 $count = 'Unknown';
                 foreach ($info as $entry) {
                     //debug($entry);
                     if ($e->uniques['pdetail'] == $entry['Pdetail']['id']) {
                         $color = $entry['Color']['name'];
                         $size = $entry['Size']['display'];
                         $count = $entry['Pdetail']['inventory'];
                     }
                 }
                 if ($count < $e->qty) {
                     $error = new MyError('inventory_level');
                     $error->setMsg('Sorry, Inventory too low for "' . $entry['Product']['name'] . '".<br/><span class="eline2">Available inventory (size: ' . $size . ', color: ' . $color . ') is <b>' . $count . '</b>.</span>');
                     array_push($errors, $error);
                 }
             }
         }
     } else {
         array_push($errors, new MyError('no_products'));
     }
     return $errors;
 }