Example #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 = $this->isCartOutOfStock($cart);
     $this->mylog('isCartOutOfStock=' . $isCartOutOfStock . '');
     $electedProduct = $this->getDejalaProduct($cart);
     $this->mylog("product\$=" . $this->logValue($electedProduct, 1));
     if (is_null($electedProduct)) {
         return "";
     }
     $acceptPartial = false;
     if (isset($electedProduct['store_attributes']) && isset($electedProduct['store_attributes']['delivery_partial']) && $electedProduct['store_attributes']['delivery_partial'] == '1') {
         $acceptPartial = true;
     }
     if ($isCartOutOfStock && !$acceptPartial) {
         return;
     }
     $djlCarrier = DejalaCarrierUtils::getCarrierByName($this->name);
     $this->mylog("electedCarrier=" . $this->logValue($djlCarrier, 1));
     if ($djlCarrier == null) {
         return null;
     }
     $dates = $electedProduct['computed_calendar']['entries'];
     // Adjust labels
     foreach ($dates as $idx => $date) {
         $dates[$idx]['label'] = $this->wday_labels[date('w', $date['ts'])] . " " . date("j", $date['ts']);
     }
     $this->mylog("date\$=" . $this->logValue($dates, 1));
     $smarty->assign('nb_days', sizeof($dates));
     $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');
     $this->mylog("electedCarrier->id=" . $this->logValue($djlCarrier->id));
     $mCarrier = $djlCarrier;
     $row['id_carrier'] = (int) $djlCarrier->id;
     $row['name'] = $this->l('Dejala.com');
     $row['price'] = $cart->getOrderShippingCost($djlCarrier->id);
     $row['price_tax_exc'] = $cart->getOrderShippingCost($djlCarrier->id, false);
     $row['img'] = _MODULE_DIR_ . $this->name . '/dejala_carrier.gif';
     if ($isCartOutOfStock) {
         $row['info'] = $this->l('I will select my shipping date when my product is available.');
     } else {
         $row['info'] = $this->l('When you want... Dispatch rider') . ', ' . $electedProduct['timelimit'] . 'H';
     }
     $resultsArray[] = $row;
     $smarty->assign('djlCarriers', $resultsArray);
     $smarty->assign('djlCarrierChecked', isset($cart->id_carrier) && $cart->id_carrier == $djlCarrier->id ? $djlCarrier->id : -1);
     $smarty->assign('product', $electedProduct);
     $djlCart = new DejalaCart($cart->id);
     $setDefaultDate = TRUE;
     $smarty->assign("deliveryDateSelected", $dates[0]['value']);
     $smarty->assign("deliveryHourSelected", $dates[0]['start_hour']);
     if ($djlCart && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) {
         $mShippingDate = $djlCart->shipping_date;
         $this->mylog("shipping_date=" . $this->logValue($mShippingDate));
         $m_hour = date("H", $mShippingDate);
         $deliveryDateSelected = date("Y/m/d", $mShippingDate);
         $this->mylog("shipping_date=" . $this->logValue($deliveryDateSelected));
         $smarty->assign("deliveryDateSelected", $deliveryDateSelected);
         $smarty->assign("deliveryHourSelected", $m_hour);
         $setDefaultDate = FALSE;
     }
     //		$smarty->assign('one_page_checkout', (Configuration::get('PS_ORDER_PROCESS_TYPE') ? Configuration::get('PS_ORDER_PROCESS_TYPE') : 0)) ;
     $smarty->assign("isCartOutOfStock", $isCartOutOfStock);
     $buffer = $this->display(__FILE__, 'dejala_carrier.tpl');
     $buffer = $buffer . $this->display(__FILE__, 'dejala_timetable.tpl');
     return $buffer;
 }
Example #2
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;
 }
Example #3
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;
 }
Example #4
0
 /**
  * Save information to enable delivery to be ordered after payment
  */
 public function hookCart($param)
 {
     global $cookie;
     $this->hooklog("hookCart", "");
     if (Tools::getIsset('ajax')) {
         return;
     }
     /**
      * Totally awful code duplication. Will have to clean this up !!
      * There's probably some unhandled cases in which the user changes his cart
      * and does not go back properly in the carrier selection process (order.php's steps).
      * He might end-up with too heavy a cart for which Dejala should not have appeared.
      * But this is not supposed to happen. 
      */
     $cart = $param['cart'];
     $carrier = new DejalaCarrier($cart->id_carrier, intval($this->id_lang));
     if ($carrier->name != 'dejala') {
         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 = new Address($cart->id_address_delivery);
     // 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 (is_null($electedProduct) || intval($electedProduct['priority']) > intval($key)) {
             $electedProduct = $product;
         }
     }
     if (is_null($electedProduct)) {
         return;
     }
     $electedCarrier = DejalaCarrierUtils::getDejalaCarrier($this->dejalaConfig, $electedProduct);
     // Should not be null at this point.
     if ($electedCarrier == null) {
         return null;
     }
     // Process the cart for storage in dejala_cart.
     $errors = array();
     $dejalaCarrierID = Tools::getValue('dejala_id_carrier');
     $carrierID = Tools::getValue('id_carrier');
     $dejalaProductID = Tools::getValue('dejala_id_product');
     if (!empty($dejalaCarrierID) && !empty($carrierID) && intval($dejalaCarrierID) == intval($carrierID)) {
         $id_cart = intval($param['cart']->id);
         $product = array();
         $djlUtil = new DejalaUtils();
         $response = $djlUtil->getStoreProductByID($this->dejalaConfig, $dejalaProductID, $product);
         if ($response['status'] != 200) {
             $errors[] = $this->l('An error occured while fetching shipping product from Dejala');
         } else {
             $timelimit = 3;
             if (isset($product['timelimit'])) {
                 $timelimit = intval($product['timelimit']);
             }
             /* manage shipping preferences */
             $date_shipping = 'NULL';
             if (isset($_POST['shipping_day']) and !empty($_POST['shipping_day']) and 10 <= strlen($_POST['shipping_day'])) {
                 $shippingHour = intval($_POST['shipping_hour']);
                 $shipping_day = $_POST['shipping_day'];
                 $ship_year = intval(substr($shipping_day, 0, 4));
                 $ship_month = intval(substr($shipping_day, 5, 2));
                 $ship_day = intval(substr($shipping_day, 8, 2));
                 $shippingTime = mktime($shippingHour, 0, 0, $ship_month, $ship_day, $ship_year);
                 // check that delivery date is in the future (5 min delay)
                 if ($shippingTime > time() - 5 * 60) {
                     $date_shipping = $shippingTime;
                 }
             }
             $djlCart = new DejalaCart($id_cart);
             $djlCart->shipping_date = $date_shipping;
             $djlCart->id_dejala_product = $dejalaProductID;
             $djlCart->id_delivery = NULL;
             $djlCart->mode = $this->dejalaConfig->mode;
             $sqlQuery = 'REPLACE INTO ' . _DB_PREFIX_ . 'dejala_cart SET id_cart = ' . intval($id_cart) . ', id_dejala_product = ' . intval($djlCart->id_dejala_product) . ', shipping_date = ' . intval($djlCart->shipping_date) . ', mode="' . pSQL($djlCart->mode) . '";';
             $this->mylog('cart SQLQuery=' . $sqlQuery);
             Db::getInstance()->Execute($sqlQuery);
         }
     }
 }
 /**
  * Checks if a Dejala carrier already exists
  */
 public static function carrierExists($dejalaConfig)
 {
     global $cookie;
     $id_zone = 1;
     $moduleCountryIsoCode = strtoupper($dejalaConfig->country);
     $countryID = Country::getByIso($moduleCountryIsoCode);
     if (intval($countryID)) {
         $id_zone = Country::getIdZone($countryID);
     }
     $allCarriers = DejalaCarrierUtils::getCarriers(intval($cookie->id_lang), true, false, $id_zone, true);
     foreach ($allCarriers as $carrier) {
         if ($carrier['name'] == 'dejala' && $carrier['is_module'] == true) {
             return true;
         }
     }
     return false;
 }
 /**
  * gets of a dejala carrier corresponding to $dejalaProduct
  */
 public static function getDejalaCarrier($dejalaConfig, $dejalaProduct)
 {
     global $cookie;
     $electedCarrier = NULL;
     $totalCartWeight = floatval($dejalaProduct['max_weight']);
     if ($totalCartWeight <= 0) {
         $totalCartWeight = 3.99;
     } else {
         $totalCartWeight -= 0.01;
     }
     /** MFR090828 - compare to HT price (since DejalaCarrier has a tax_id) */
     $vat_factor = 1 + $dejalaProduct['vat'] / 100;
     $priceTTC = round($dejalaProduct['price'] * $vat_factor + $dejalaProduct['margin'], 2);
     $priceHT = round($priceTTC / $vat_factor, 2);
     $productPrice = $priceHT;
     // MFR091130 - get id zone from the country used in the module (if the store zones were customized)
     // default (Europe)
     $id_zone = 1;
     $moduleCountryIsoCode = strtoupper($dejalaConfig->country);
     $countryID = Country::getByIso($moduleCountryIsoCode);
     if (intval($countryID)) {
         $id_zone = Country::getIdZone($countryID);
     }
     $allCarriers = DejalaCarrierUtils::getCarriers(intval($cookie->id_lang), true, false, $id_zone, true);
     $electedCarrier = NULL;
     foreach ($allCarriers as $carrier) {
         if ($carrier['name'] == 'dejala' && $carrier['range_behavior'] && Configuration::get('PS_SHIPPING_METHOD') && Carrier::checkDeliveryPriceByWeight($carrier['id_carrier'], $totalCartWeight, $id_zone)) {
             $mCarrier = new Carrier($carrier['id_carrier']);
             if ($productPrice == $mCarrier->getDeliveryPriceByWeight($totalCartWeight, $id_zone)) {
                 if ($electedCarrier == NULL) {
                     $electedCarrier = $mCarrier;
                 } else {
                     if ($mCarrier->id < $electedCarrier->id) {
                         $electedCarrier = $mCarrier;
                     }
                 }
             }
         }
     }
     return $electedCarrier;
 }