Beispiel #1
0
 /**
  * Update promos on order items
  *  - and Add drupal Item Names
  *
  * @param $o
  * @param string $locale
  */
 private function updatePromosAddDrupal(&$o, $locale = 'en_US')
 {
     $this->PromotionalProduct = ClassRegistry::init('PromotionalProduct');
     $this->NsWarehouse = ClassRegistry::init('NsWarehouse');
     $this->Item = ClassRegistry::init('Item');
     foreach ($o['OrderCustomer']['OrderItem'] as $ik => &$item) {
         /**
          * Set backorder restock date
          */
         if (!empty($item['OrderItemRestock'][0]['restock_date']) && $item['order_item_hold_code_id'] == OrderItemHoldCode::BACKORDERED) {
             $item['estimated_date'] = $item['OrderItemRestock'][0]['restock_date'];
         } else {
             $item['estimated_date'] = null;
         }
         $wid = $item['ns_warehouse_id'];
         $date = $item['date_created'];
         $bo_date = $this->NsWarehouse->backOrderStartDate($date, $item['Item']['sku'], $wid);
         if (!empty($bo_date)) {
             $item['backorder_start'] = $bo_date;
         }
         /**
          * Set drupal data
          */
         $item['Item']['name'] = DruniqueAPIUtil::drupalName($item, $locale);
         $promo = $this->PromotionalProduct->find('first', ['conditions' => ['reward_sku' => $item['Item']['sku']]]);
         $item['Item']['PromotionalProduct'] = $promo['PromotionalProduct'];
     }
 }
 /**
  * Backorders v2 UI - Returns an array containing the item name from Drupal
  * If the returned value is false, the sku name was not found.
  * If the returned value is a string, an error has occured and the string is error message
  * @param $locale
  * @return array | boolean:false | string
  */
 public function getItemName($locale)
 {
     $criteria = ['contain' => ['ParentItems'], 'conditions' => ['Item.sku' => $this->sku]];
     try {
         $item = $this->Item->find('first', $criteria);
         // update to work with DruniqueAPIUtil::drupalName
         $item['Item']['ParentItems'] = $item['ParentItems'];
         unset($item['ParentItems']);
         $item_name = DruniqueAPIUtil::drupalName($item, $locale);
     } catch (Exception $e) {
         return $e->getMessage();
     }
     // if Drupal didn't return anything use the $item object if possible
     if (empty($item_name)) {
         if (empty($item)) {
             return false;
         }
         $p_name = $item['Item']['ParentItems']['name'];
         $item_name = (empty($p_name) ? '' : $p_name . ' - ') . $item['Item']['name'];
     }
     // put the item name into an array
     $data['Item'] = array('name' => $item_name);
     return $data;
 }