Esempio n. 1
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;
 }
Esempio n. 2
0
 /**
  * Handle drawing time list.
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_Times($tag_params, $children)
 {
     $manager = IntervalTimeManager::getInstance();
     $conditions = array();
     $order_by = array('start');
     if (isset($tag_params['interval'])) {
         $conditions['interval'] = fix_id($tag_params['interval']);
     } else {
         $conditions['interval'] = -1;
     }
     // get all times
     $times = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, True);
     // load template
     $template = $this->loadTemplate($tag_params, 'time.xml');
     if (count($times) > 0) {
         foreach ($times as $time) {
             $params = array('start' => $time->start, 'end' => $time->end, 'price' => $time->amount);
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }