Esempio n. 1
0
 /**
  *
  * @return string
  */
 public function showComponents()
 {
     $html = '';
     foreach (KitComponent::getAllByCriteria('kitId=?', array($this->kit->getId())) as $index => $kitComponent) {
         $html .= $this->getRow($kitComponent->getQty(), $kitComponent->getComponent()->getSku(), $kitComponent->getComponent()->getName(), 'itemRow');
     }
     return $html;
 }
Esempio n. 2
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::getJson()
  */
 public function getJson($extra = array(), $reset = false)
 {
     $array = $extra;
     if (!$this->isJsonLoaded($reset)) {
         $array['task'] = $this->getTask() instanceof Task ? $this->getTask()->getJson() : null;
         $array['product'] = $this->getProduct() instanceof Product ? $this->getProduct()->getJson() : null;
         $array['soldToCustomer'] = $this->getSoldToCustomer() instanceof Customer ? $this->getSoldToCustomer()->getJson() : null;
         $array['soldOnOrder'] = $this->getSoldOnOrder() instanceof Order ? $this->getSoldOnOrder()->getJson() : null;
         $array['shippment'] = $this->getShippment() instanceof Shippment ? $this->getShippment()->getJson() : null;
         $array['components'] = array_map(create_function('$a', 'return $a->getJson();'), KitComponent::getAllByCriteria('kitId = ?', array($this->getId())));
     }
     return parent::getJson($array, $reset);
 }
Esempio n. 3
0
 /**
  * Creating a kitcomponent
  *
  * @param Kit     $kit
  * @param Product $component
  * @param number  $qty
  *
  * @return KitComponent
  */
 public static function create(Kit &$kit, Product $component, $qty, $unitPrice = '')
 {
     $kitComponent = new KitComponent();
     return $kitComponent->setKit($kit)->setComponent($component)->setQty(intval($qty))->setUnitPrice($unitPrice)->save();
 }
Esempio n. 4
0
 /**
  * (non-PHPdoc)
  * @see DetailsPageAbstract::saveItem()
  */
 public function saveItem($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         $kit = !isset($param->CallbackParameter->id) ? new Kit() : Kit::get(trim($param->CallbackParameter->id));
         if (!$kit instanceof Kit) {
             throw new Exception('Invalid Kit passed in!');
         }
         if (!isset($param->CallbackParameter->productId) || !($product = Product::get(trim($param->CallbackParameter->productId))) instanceof Product) {
             throw new Exception('Invalid Kit Product passed in!');
         }
         if (!isset($param->CallbackParameter->items) || count($items = $param->CallbackParameter->items) === 0) {
             throw new Exception('No Kit Components passed in!');
         }
         $task = null;
         if (isset($param->CallbackParameter->taskId) && !($task = Task::get(trim($param->CallbackParameter->taskId))) instanceof Task) {
             throw new Exception('Invalid Task passed in!');
         }
         $underCostReason = '';
         if (isset($param->CallbackParameter->underCostReason) && ($underCostReason = trim($param->CallbackParameter->underCostReason)) === '') {
             throw new Exception('UnderCostReason is Required!');
         }
         $isNewKit = false;
         if (trim($kit->getId()) === '') {
             $kit = Kit::create($product, $task);
             $isNewKit = true;
         } else {
             $kit->setTask($task)->save();
         }
         //add all the components
         foreach ($items as $item) {
             if (!($componentProduct = Product::get(trim($item->productId))) instanceof Product) {
                 continue;
             }
             if (($componentId = trim($item->id)) === '' && intval($item->active) === 1) {
                 $kit->addComponent($componentProduct, intval($item->qty));
             } else {
                 if (($kitComponent = KitComponent::get($componentId)) instanceof KitComponent) {
                     if ($kitComponent->getKit()->getId() !== $kit->getId()) {
                         continue;
                     }
                     if (intval($item->active) === 0) {
                         //deactivation
                         $kitComponent->setActive(false)->save();
                     } else {
                         $kitComponent->setQty(intval($item->qty))->save();
                     }
                 }
             }
         }
         if (trim($underCostReason) !== '') {
             $kit->addComment('The reason for continuing bulding this kit, when its cost is greater than its unit price: ' . $underCostReason, Comments::TYPE_WORKSHOP);
         }
         if ($isNewKit === true) {
             $kit->finishedAddingComponents();
         }
         $results['url'] = '/kit/' . $kit->getId() . '.html' . (trim($_SERVER['QUERY_STRING']) === '' ? '' : '?' . $_SERVER['QUERY_STRING']);
         if ($isNewKit === true) {
             $results['printUrl'] = '/print/kit/' . $kit->getId() . '.html?printlater=1';
         }
         $results['createdFromNew'] = $isNewKit;
         $results['item'] = $kit->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage() . '<pre>' . $ex->getTraceAsString() . '</pre>';
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }