示例#1
0
 /**
  ** Affiche le transporteur Dejala.com dans la liste des transporteurs sur le Front Office
  */
 public function hookExtraCarrier($params)
 {
     global $smarty, $defaultCountry;
     $cart = $params['cart'];
     $cookie = $params['cookie'];
     $this->hooklog("ExtraCarrier", $params);
     // Check if Dejala should be visible
     if ($this->dejalaConfig->visibility_status == "invisible") {
         return;
     }
     if ($this->dejalaConfig->visibility_status == "visible_limited" && (int) $cookie->id_customer > 0) {
         $customer = new Customer((int) $cookie->id_customer);
         if (!in_array($customer->email, preg_split("/[\\s,]+/", $this->dejalaConfig->visible_users_list))) {
             return;
         }
     }
     $djlUtil = new DejalaUtils();
     $responseGetStore = $djlUtil->getStoreAttributes($this->dejalaConfig, $store);
     if ($responseGetStore['status'] != '200') {
         return;
     }
     $isCartOutOfStock = '0';
     if ($this->isCartOutOfStock($cart)) {
         $isCartOutOfStock = '1';
     }
     $this->mylog('isCartOutOfStock=' . $isCartOutOfStock . '');
     $acceptPartial = true;
     if (!isset($store['attributes']) || !isset($store['attributes']['delivery_partial']) || $store['attributes']['delivery_partial'] != '1') {
         $acceptPartial = false;
     }
     if ($isCartOutOfStock == '1' && !$acceptPartial) {
         return;
     }
     $electedProduct = $this->getDejalaProduct($cart);
     // Get id zone
     if (isset($cart->id_address_delivery) and $cart->id_address_delivery) {
         $id_zone = (int) Address::getZoneById((int) $cart->id_address_delivery);
     } else {
         $id_zone = (int) $defaultCountry->id_zone;
     }
     $djlCarrier = DejalaCarrierUtils::getCarrierByName($this->name);
     $this->mylog("electedCarrier=" . $this->logValue($djlCarrier, 1));
     if ($djlCarrier == null) {
         return null;
     }
     // Calcul des dates dispo
     $productCalendar = $electedProduct['calendar']['entries'];
     // MFR090831 - add picking time : the store is open to (stop_hour - picking time), it is more natural to merchants to set opening hours instead of dejala delivery time
     if ($electedProduct['pickingtime']) {
         $pickingtime = (int) $electedProduct['pickingtime'];
     } else {
         $pickingtime = $electedProduct['timelimit'];
     }
     $djlUtil = new DejalaUtils();
     $storeCalendar = array();
     $calendar = array();
     $response = $djlUtil->getStoreCalendar($this->dejalaConfig, $storeCalendar);
     $this->mylog("productCalendar=" . $this->logValue($productCalendar, 1));
     $this->mylog("storeCalendar=" . $this->logValue($storeCalendar, 1));
     $this->mylog("response['status']=" . $response['status']);
     if ($response['status'] == 200) {
         foreach ($storeCalendar['entries'] as $weekday => $calEntry) {
             if (isset($productCalendar[$weekday])) {
                 $calendar[$weekday]["weekday"] = $weekday;
                 $calendar[$weekday]["start_hour"] = max((int) $productCalendar[$weekday]["start_hour"], (int) $calEntry["start_hour"]);
                 // MFR090831 - manage picking time : the store is open to (stop_hour - picking time)
                 $calendar[$weekday]["stop_hour"] = min((int) ($productCalendar[$weekday]["stop_hour"] - 1), (int) ($calEntry["stop_hour"] - $pickingtime));
                 if ($calendar[$weekday]["stop_hour"] < $calendar[$weekday]["start_hour"]) {
                     unset($calendar[$weekday]);
                 }
             }
         }
     }
     // Calcul de la date de démarrage pour les créneaux :
     // Avancement jusque jour dispo & ouvert
     // Ajout du temps de préparation : 0.5 jour ou 1 nb de jours
     // Ajustement de l'heure sur l'ouverture ou l'heure suivante xxh00
     $deliveryDelay = $store['attributes']['delivery_delay'];
     $skipCurDay = false;
     $calUtils = new CalendarUtils();
     $all_exceptions = array_merge($storeCalendar['exceptions'], $electedProduct['calendar']['exceptions']);
     $dateUtc = $calUtils->getNextDateAvailable(time(), $calendar, $all_exceptions);
     if ($dateUtc == NULL) {
         return;
     }
     if ($deliveryDelay > 0) {
         if ($skipCurDay) {
             $dateUtc = $calUtils->skipCurDay($dateUtc);
         }
         $dateUtc = $calUtils->addDelay($dateUtc, $deliveryDelay, $calendar, $all_exceptions);
     }
     if ($dateUtc == NULL) {
         return;
     }
     $dateUtc = $calUtils->adjustHour($dateUtc, $calendar);
     $this->mylog("calendar=" . $this->logValue($calendar, 1));
     $this->mylog("starting date=" . $this->logValue(date("d/m/Y - H:i:s", $dateUtc), 1));
     $today = getDate();
     $ctime = time();
     $nbDeliveryDates = $deliveryDelay = $store['attributes']['nb_days_displayed'];
     $iDate = 0;
     $dates = array();
     $balladUtc = $dateUtc;
     do {
         $wd = date("w", $balladUtc);
         if ((int) $calendar[$wd]['stop_hour'] < (int) $calendar[$wd]['start_hour']) {
             continue;
         }
         $dates[$iDate]['value'] = date("Y/m/d", $balladUtc);
         $dates[$iDate]['ts'] = $balladUtc;
         $dates[$iDate]['label'] = $this->wday_labels[$wd] . " " . date("j", $balladUtc);
         $dates[$iDate]['start_hour'] = (int) $calendar[$wd]['start_hour'];
         $dates[$iDate]['stop_hour'] = (int) $calendar[$wd]['stop_hour'];
         $balladUtc = strtotime(date("Y-m-d", $balladUtc) . " +1 day");
         $balladUtc = mktime(0, 0, 0, date('m', $balladUtc), date('d', $balladUtc), date('Y', $balladUtc));
         $balladUtc = $calUtils->getNextDateAvailable($balladUtc, $calendar, $all_exceptions);
         $iDate++;
     } while ($iDate < $nbDeliveryDates && $balladUtc);
     // impossibilité de trouver un jour dispo
     if (!isset($dates[0])) {
         return;
     }
     $now = (int) date("H", $ctime);
     if ((int) $dates[0]['stop_hour'] > $now && (int) $dates[0]['start_hour'] < $now) {
         $dates[0]['start_hour'] = $now;
     } elseif ((int) $dates[0]['ts'] == $now && (int) $dates[0]['stop_hour'] < $now) {
         array_shift($dates);
     }
     $this->mylog("date\$=" . $this->logValue($dates, 1));
     $smarty->assign('nb_days', $nbDeliveryDates);
     $smarty->assign('dates', $dates);
     for ($i = 0; $i < 24; $i++) {
         $endHour = ($i + $electedProduct['timelimit']) % 24;
         if ($endHour == 0) {
             $endHour = 24;
         }
         $hourLabels[] = $i . 'h-' . $endHour . 'h';
     }
     $smarty->assign('hourLabels', $hourLabels);
     $smarty->assign('timetable_css', _MODULE_DIR_ . $this->name . '/timetable.css');
     $smarty->assign("timetable_js", _MODULE_DIR_ . $this->name . '/timetable.js');
     $this->mylog("electedCarrier->id=" . $this->logValue($djlCarrier->id));
     $mCarrier = $djlCarrier;
     $row['id_carrier'] = (int) $djlCarrier->id;
     $row['name'] = $this->l('Dejala.com');
     $row['delay'] = $this->l('When you want... Dispatch rider') . ', ' . $electedProduct['timelimit'] . 'H';
     $row['price'] = $cart->getOrderShippingCost($djlCarrier->id);
     $row['price_tax_exc'] = $cart->getOrderShippingCost($djlCarrier->id, false);
     $row['img'] = _MODULE_DIR_ . $this->name . '/dejala_carrier.gif';
     $resultsArray[] = $row;
     $smarty->assign('carriers', $resultsArray);
     $smarty->assign('my_carrier_selected', isset($cart->id_carrier) && $cart->id_carrier == $djlCarrier->id);
     $smarty->assign('product', $electedProduct);
     $djlCart = new DejalaCart($cart->id);
     $setDefaultDate = TRUE;
     if ($djlCart && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) {
         $mShippingDate = $djlCart->shipping_date;
         $this->mylog("shipping_date=" . $this->logValue($mShippingDate));
         $m_day = date("d", $mShippingDate);
         $m_hour = date("H", $mShippingDate);
         $deliveryDateSelected = date("Y/m/d", $mShippingDate);
         $this->mylog("shipping_date=" . $this->logValue($deliveryDateSelected));
         foreach ($dates as $l_key => $l_date) {
             if ($l_date['value'] == $deliveryDateSelected) {
                 $smarty->assign("deliveryDateIndexSelected", $l_key);
                 $smarty->assign("deliveryDateSelected", $deliveryDateSelected);
                 $smarty->assign("deliveryHourSelected", $m_hour);
                 $setDefaultDate = FALSE;
             }
         }
     }
     if ($setDefaultDate) {
         $smarty->assign("deliveryDateIndexSelected", 0);
         $smarty->assign("deliveryDateSelected", date("Y/m/d", $dateUtc));
         $smarty->assign("deliveryHourSelected", (int) date("H", $dateUtc));
     }
     $smarty->assign("isCartOutOfStock", $isCartOutOfStock);
     if (!$isCartOutOfStock) {
         $buffer = $this->display(__FILE__, 'dejala_carrier.tpl');
         $buffer = $buffer . $this->display(__FILE__, 'dejala_timetable.tpl');
     } else {
         $smarty->assign('nostock_info', $this->l('I will select my shipping date when my product is available.'));
         $buffer = $this->display(__FILE__, 'dejala_carrier_nostock.tpl');
     }
     return $buffer;
 }
示例#2
0
 /**
  ** Affiche le transporteur Dejala.fr dans la liste des transporteurs sur le Front Office
  */
 public function hookExtraCarrier($params)
 {
     global $smarty, $cart, $cookie, $defaultCountry;
     $this->hooklog("ExtraCarrier", $params);
     // Dejala n'est pas actif sur la boutique
     if ($this->dejalaConfig->active != 1) {
         return;
     }
     $djlUtil = new DejalaUtils();
     $responseGetStore = $djlUtil->getStoreAttributes($this->dejalaConfig, $store);
     if ($responseGetStore['status'] != '200') {
         return;
     }
     $isCartOutOfStock = '0';
     if ($this->isCartOutOfStock()) {
         $isCartOutOfStock = '1';
     }
     $this->mylog('isCartOutOfStock=' . $isCartOutOfStock . '');
     $acceptPartial = true;
     if (!isset($store['attributes']) || !isset($store['attributes']['delivery_partial']) || $store['attributes']['delivery_partial'] != '1') {
         $acceptPartial = false;
     }
     if ($isCartOutOfStock == '1' && !$acceptPartial) {
         return;
     }
     $totalCartWeight = floatval($cart->getTotalWeight());
     $address = $params['address'];
     // ask dejala.fr for a quotation
     $quotation["receiver_name"] = $address->lastname;
     $quotation["receiver_firstname"] = $address->firstname;
     $quotation["receiver_company"] = $address->company;
     $quotation["receiver_address"] = $address->address1;
     $quotation["receiver_address2"] = $address->address2;
     $quotation["receiver_zipcode"] = $address->postcode;
     $quotation["receiver_city"] = $address->city;
     $quotation["receiver_phone"] = $address->phone;
     $quotation["receiver_phone_mobile"] = $address->phone_mobile;
     $quotation["receiver_comments"] = $address->other;
     $quotation["timelimit"] = 3;
     $quotation["weight"] = $totalCartWeight;
     $this->mylog("asking for quotation=" . $this->logValue($quotation, 1));
     $products = array();
     $responseArray = $djlUtil->getStoreQuotation($this->dejalaConfig, $quotation, $products);
     if ($responseArray['status'] != '200') {
         return;
     }
     $this->mylog("found quotation=" . $this->logValue($responseArray['response'], 1));
     $electedProduct = NULL;
     foreach ($products as $key => $product) {
         //	if (floatval($product['max_weight']) >= $totalCartWeight) {
         if (is_null($electedProduct) || intval($electedProduct['priority']) > intval($key)) {
             $electedProduct = $product;
         }
         //	}
     }
     if (is_null($electedProduct)) {
         return;
     }
     $this->mylog("electedProduct=" . $this->logValue($electedProduct, 1));
     $electedCarrier = DejalaCarrierUtils::getDejalaCarrier($this->dejalaConfig, $electedProduct);
     $this->mylog("electedCarrier=" . $this->logValue($electedCarrier, 1));
     if (null == $electedCarrier) {
         $this->mylog("creating a new carrier");
         $electedCarrier = DejalaCarrierUtils::createDejalaCarrier($this->dejalaConfig, $electedProduct);
     }
     // Calcul des dates dispo
     $productCalendar = $electedProduct['calendar']['entries'];
     // MFR090831 - add picking time : the store is open to (stop_hour - picking time), it is more natural to merchants to set opening hours instead of dejala delivery time
     if ($electedProduct['pickingtime']) {
         $pickingtime = intval($electedProduct['pickingtime']);
     } else {
         $pickingtime = $electedProduct['timelimit'];
     }
     $djlUtil = new DejalaUtils();
     $storeCalendar = array();
     $calendar = array();
     $response = $djlUtil->getStoreCalendar($this->dejalaConfig, $storeCalendar);
     $this->mylog("productCalendar=" . $this->logValue($productCalendar, 1));
     $this->mylog("storeCalendar=" . $this->logValue($storeCalendar, 1));
     $this->mylog("response['status']=" . $response['status']);
     if ($response['status'] == 200) {
         foreach ($storeCalendar['entries'] as $weekday => $calEntry) {
             if (isset($productCalendar[$weekday])) {
                 $calendar[$weekday]["weekday"] = $weekday;
                 $calendar[$weekday]["start_hour"] = max(intval($productCalendar[$weekday]["start_hour"]), intval($calEntry["start_hour"]));
                 // MFR090831 - manage picking time : the store is open to (stop_hour - picking time)
                 $calendar[$weekday]["stop_hour"] = min(intval($productCalendar[$weekday]["stop_hour"] - 1), intval($calEntry["stop_hour"] - $pickingtime));
                 if ($calendar[$weekday]["stop_hour"] < $calendar[$weekday]["start_hour"]) {
                     unset($calendar[$weekday]);
                 }
             }
         }
     }
     // Calcul de la date de démarrage pour les créneaux :
     // Avancement jusque jour dispo & ouvert
     // Ajout du temps de préparation : 0.5 jour ou 1 nb de jours
     // Ajustement de l'heure sur l'ouverture ou l'heure suivante xxh00
     $deliveryDelay = $store['attributes']['delivery_delay'];
     $calUtils = new CalendarUtils();
     $all_exceptions = array_merge($storeCalendar['exceptions'], $electedProduct['calendar']['exceptions']);
     $dateUtc = $calUtils->getNextDateAvailable(time(), $calendar, $all_exceptions);
     if ($dateUtc == NULL) {
         return;
     }
     if ($deliveryDelay > 0) {
         $dateUtc = $calUtils->addDelay($dateUtc, $deliveryDelay, $calendar, $all_exceptions);
     }
     if ($dateUtc == NULL) {
         return;
     }
     $dateUtc = $calUtils->adjustHour($dateUtc, $calendar);
     $this->mylog("calendar=" . $this->logValue($calendar, 1));
     $this->mylog("starting date=" . $this->logValue(date("d/m/Y - H:i:s", $dateUtc), 1));
     /**
     		 Dates[0] = {
     		 [label]=lundi
     		 [value]=23/04/2009
     		 [start_hour]=9
     		 [stop_hour]=17
     		 }
     		 **/
     $today = getDate();
     $ctime = time();
     $wday_labels = array($this->l('Dimanche'), $this->l('Lundi'), $this->l('Mardi'), $this->l('Mercredi'), $this->l('Jeudi'), $this->l('Vendredi'), $this->l('Samedi'));
     $nbDeliveryDates = $deliveryDelay = $store['attributes']['nb_days_displayed'];
     $iDate = 0;
     $dates = array();
     $balladUtc = $dateUtc;
     do {
         $dates[$iDate]['value'] = date("Y/m/d", $balladUtc);
         $wd = date("w", $balladUtc);
         $dates[$iDate]['label'] = $wday_labels[$wd] . " " . date("j", $balladUtc);
         $dates[$iDate]['start_hour'] = $calendar[$wd]['start_hour'];
         $dates[$iDate]['stop_hour'] = $calendar[$wd]['stop_hour'];
         $balladUtc += 3600 * 24;
         $balladUtc = $calUtils->getNextDateAvailable($balladUtc, $calendar, $all_exceptions);
         $iDate++;
     } while ($iDate < $nbDeliveryDates && $balladUtc);
     // impossibilité de trouver un jour dispo
     if (!isset($dates[0])) {
         return;
     }
     $dates[0]['start_hour'] = date("H", $dateUtc);
     $this->mylog("date\$=" . $this->logValue($dates, 1));
     $smarty->assign('nb_days', $nbDeliveryDates);
     $smarty->assign('dates', $dates);
     for ($i = 0; $i < 24; $i++) {
         $endHour = ($i + $electedProduct['timelimit']) % 24;
         if ($endHour == 0) {
             $endHour = 24;
         }
         $hourLabels[] = $i . 'h-' . $endHour . 'h';
     }
     $smarty->assign('hourLabels', $hourLabels);
     $smarty->assign('timetable_css', _MODULE_DIR_ . $this->name . '/timetable.css');
     $smarty->assign("timetable_js", _MODULE_DIR_ . $this->name . '/timetable.js');
     $this->mylog("electedCarrier->id=" . $this->logValue($electedCarrier->id));
     $mCarrier = $electedCarrier;
     $row['id_carrier'] = intval($electedCarrier->id);
     $row['name'] = $this->l('Dejala.fr');
     $row['delay'] = $electedCarrier->delay[$cookie->id_lang];
     $row['price'] = $cart->getOrderShippingCost($electedCarrier->id);
     $row['price_tax_exc'] = $cart->getOrderShippingCost($electedCarrier->id, false);
     $row['img'] = _MODULE_DIR_ . $this->name . '/dejala_carrier.gif';
     $resultsArray[] = $row;
     $smarty->assign('carriers', $resultsArray);
     if ($cart->id_carrier) {
         $smarty->assign('checked', $cart->id_carrier);
     }
     $smarty->assign('product', $electedProduct);
     $djlCart = new DejalaCart($cart->id);
     $setDefaultDate = TRUE;
     if ($djlCart && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) {
         $mShippingDate = $djlCart->shipping_date;
         $this->mylog("shipping_date=" . $this->logValue($mShippingDate));
         $m_day = date("d", $mShippingDate);
         $m_hour = date("H", $mShippingDate);
         $deliveryDateSelected = date("Y/m/d", $mShippingDate);
         $this->mylog("shipping_date=" . $this->logValue($deliveryDateSelected));
         foreach ($dates as $l_key => $l_date) {
             if ($l_date['value'] == $deliveryDateSelected) {
                 $smarty->assign("deliveryDateIndexSelected", $l_key);
                 $smarty->assign("deliveryDateSelected", $deliveryDateSelected);
                 $smarty->assign("deliveryHourSelected", $m_hour);
                 $setDefaultDate = FALSE;
             }
         }
     }
     if ($setDefaultDate) {
         $smarty->assign("deliveryDateIndexSelected", 0);
         $smarty->assign("deliveryDateSelected", date("Y/m/d", $dateUtc));
         $smarty->assign("deliveryHourSelected", intval(date("H", $dateUtc)));
     }
     $smarty->assign("isCartOutOfStock", $isCartOutOfStock);
     if (!$isCartOutOfStock) {
         $buffer = $this->display(__FILE__, 'dejala_carrier.tpl');
         $buffer = $buffer . $this->display(__FILE__, 'dejala_timetable.tpl');
     } else {
         $smarty->assign('nostock_info', $this->l(utf8_encode('Je choisirai mon heure de livraison quand mon colis sera prêt.')));
         $buffer = $this->display(__FILE__, 'dejala_carrier_nostock.tpl');
     }
     return $buffer;
 }