Ejemplo n.º 1
0
 /**
  * install dejala module
  */
 public function install()
 {
     if (!file_exists(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE)) {
         return false;
     } elseif (!($sql = file_get_contents(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE))) {
         return false;
     }
     $sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql);
     $sql = preg_split("/;\\s*[\r\n]+/", $sql);
     foreach ($sql as $query) {
         if (!empty($query)) {
             if (!Db::getInstance()->Execute(trim($query))) {
                 return false;
             }
         }
     }
     if (parent::install() == false or $this->registerHook('updateOrderStatus') == false or $this->registerHook('extraCarrier') == false or $this->registerHook('processCarrier') == false) {
         return false;
     }
     $this->dejalaConfig = new DejalaConfig();
     if (!$this->dejalaConfig->saveConfig()) {
         return false;
     }
     DejalaCarrierUtils::createDejalaCarrier($this->dejalaConfig);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * install dejala module
  */
 public function install()
 {
     if (!file_exists(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE)) {
         return false;
     } elseif (!($sql = file_get_contents(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE))) {
         return false;
     }
     $sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql);
     $sql = preg_split("/;\\s*[\r\n]+/", $sql);
     foreach ($sql as $query) {
         if (!empty($query)) {
             if (!Db::getInstance()->Execute(trim($query))) {
                 return false;
             }
         }
     }
     if (parent::install() == false or $this->registerHook('updateOrderStatus') == false or $this->registerHook('extraCarrier') == false or $this->registerHook('processCarrier') == false or $this->registerHook('orderDetailDisplayed') == false or $this->registerHook('PDFInvoice') == false) {
         return false;
     }
     $this->dejalaConfig = new DejalaConfig();
     if (!$this->dejalaConfig->saveConfig()) {
         return false;
     }
     // Cleanup pre-existing Dejala Carriers (in case the module had previously been tested and not removed cleanly)
     while (!is_null($carrier = DejalaCarrierUtils::getCarrierByName($this->name, true))) {
         $carrier->deleted = 1;
         if (!$carrier->update()) {
             return false;
         }
     }
     DejalaCarrierUtils::createDejalaCarrier($this->dejalaConfig);
     return true;
 }
Ejemplo n.º 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;
 }