Exemplo n.º 1
0
 /**
  * Public function that creates a single instance
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Exemplo n.º 2
0
 /**
  * Get available delivery types for selected items. Each type needs
  * to return estimated delivery time, cost and name of service.
  *
  * Example of items array:
  * 		$items = array(
  * 					array(
  * 						'package'		=> 0, // number identifying package
  * 						'properties'	=> array(),
  * 						'package_type'	=> 0,
  * 						'width'			=> 0.2,
  * 						'height'		=> 0.5,
  * 						'length'		=> 1,
  * 						'weight'		=> 0,
  * 						'units'			=> 1,
  * 						'count'			=> 1
  * 					)
  * 				);
  *
  * Example of shipper array:
  * 		$shipper = array(
  * 					'street'	=> array(),
  * 					'city'		=> '',
  * 					'zip_code'	=> '',
  * 					'state'		=> '',
  * 					'country'	=> ''
  * 				);
  *
  * Example of recipient array:
  * 		$recipient = array(
  * 					'street'	=> array(),
  * 					'city'		=> '',
  * 					'zip_code'	=> '',
  * 					'state'		=> '',
  * 					'country'	=> ''
  * 				);
  *
  * Example of result array:
  *		$result = array(
  *					'normal' => array('Normal', 19.95, 'USD', 1364040000, 1365040000),
  *					'express' => array('Express', 33.23, 'USD', 1363040000, 1364040000),
  *					'express_no_estimate' => array('Express', 8.00, 'USD', false, false)
  *				);
  *
  * @param array $items
  * @param array $shipper
  * @param array $recipient
  * @param string $transaction_id
  * @param string $preferred_currency
  * @return array
  */
 public function getDeliveryTypes($items, $shipper, $recipient, $transaction_id, $preferred_currency)
 {
     $shop = shop::getInstance();
     $manager = IntervalManager::getInstance();
     $time_manager = IntervalTimeManager::getInstance();
     $days = array();
     $result = array();
     // load all delivery intervals
     $intervals = $manager->getItems($manager->getFieldNames(), array());
     if (count($intervals) == 0) {
         return $result;
     }
     foreach ($intervals as $interval) {
         // get hours
         $times = $time_manager->getItems($time_manager->getFieldNames(), array('interval' => $interval->id));
         // make sure there are hours defined in this interval
         if (count($times) == 0) {
             continue;
         }
         // collect delivery hours
         for ($i = 0; $i < 7; $i++) {
             if ($interval->days[$i] == '1') {
                 if (!isset($days[$i])) {
                     $days[$i] = array();
                 }
                 foreach ($times as $time) {
                     $days[$i][] = $time;
                 }
             }
         }
     }
     // calculate shipping dates for specified number of days
     $today = mktime(0, 0, 0);
     $date_format = $this->parent->getLanguageConstant('format_date_short');
     $time_format = $this->parent->getLanguageConstant('format_time_short');
     $currency = $shop->getDefaultCurrency();
     for ($i = 0; $i < $this->days_to_show; $i++) {
         $current_date = $today + $i * (24 * 60 * 60);
         $day_of_week = (int) date('N', $current_date) - 1;
         // skip day if there are no deliveries
         if (!isset($days[$day_of_week])) {
             continue;
         }
         // add intervals
         foreach ($days[$day_of_week] as $time) {
             $start = strtotime($time->start, $current_date);
             $end = strtotime($time->end, $current_date);
             // skip past intervals
             if (time() > $start) {
                 continue;
             }
             // add new delivery date
             $key = date($date_format . ' ' . $time_format, $start);
             $result[$key] = array($this->parent->getLanguageConstant('label_' . ($day_of_week + 1)), $time->amount, $currency, $start, $end);
         }
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * Tag handler for interval list.
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_IntervalList($tag_params, $children)
 {
     $manager = IntervalManager::getInstance();
     $conditions = array();
     // get intervals
     $intervals = $manager->getItems($manager->getFieldNames(), $conditions);
     // load template
     $template = $this->loadTemplate($tag_params, 'list_item.xml');
     $template->registerTagHandler('cms:days', $this, 'tag_Days');
     $template->registerTagHandler('cms:times', $this, 'tag_Times');
     // parse template
     if (count($intervals) > 0) {
         foreach ($intervals as $interval) {
             $params = array('id' => $interval->id, 'days' => $interval->days, 'enabled' => $interval->enabled, 'item_change' => url_MakeHyperlink($this->getLanguageConstant('change'), window_Open('delivery_intervals_change', 500, $this->getLanguageConstant('title_interval_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'intervals_change'), array('id', $interval->id)))), 'item_delete' => url_MakeHyperlink($this->getLanguageConstant('delete'), window_Open('delivery_intervals_delete', 400, $this->getLanguageConstant('title_interval_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'intervals_delete'), array('id', $interval->id)))));
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }