return $l_array; } global $smarty; $dejalaConfig = new DejalaConfig(); $dejalaConfig->loadConfig(); $from = Tools::getValue('datepickerFrom'); $to = Tools::getValue('datepickerTo'); if (!is_null($from) && !is_null($to) && strlen($from) == 10 && strlen($to) == 10) { $dateFrom = mktime(0, 0, 1, intval(substr($from, 3, 2)), intval(substr($from, 0, 2)), intval(substr($from, 6, 4))); $dateTo = mktime(23, 59, 59, intval(substr($to, 3, 2)), intval(substr($to, 0, 2)), intval(substr($to, 6, 4))); if ($dateFrom > $dateTo) { $tmp = $dateTo; $dateTo = $dateFrom; $dateFrom = $tmp; } $djlUtil = new DejalaUtils(); $deliveries = array(); $responseArray = $djlUtil->getStoreDeliveries($dejalaConfig, $deliveries, array('from_utc' => $dateFrom, 'to_utc' => $dateTo)); if ($responseArray['status'] = '200') { $l_deliveries = array(); header("Content-type: text/csv"); header("Content-disposition: attachment; filename=\"deliveries.csv\""); foreach ($deliveries as $key => $delivery) { $l_delivery = doubleQuoteArray($delivery); $l_delivery['price'] = ereg_replace('\\.', ',', $l_delivery['price']); $l_delivery['creation_date'] = date('d/m/Y', $delivery['creation_utc']); $l_delivery['creation_time'] = date('H\\hi', $delivery['creation_utc']); if (isset($delivery['shipping_start_utc'])) { $l_delivery['shipping_date'] = date('d/m/Y', $delivery['shipping_start_utc']); $l_delivery['shipping_start'] = date('H\\hi', $delivery['shipping_start_utc']); $l_delivery['shipping_stop'] = date('H\\hi', intval($delivery['shipping_start_utc']) + 3600 * intval($delivery['timelimit']));
private function getDejalaProduct($cart, $productId = -1) { // echo "Date : " . $cart->date_upd . "<br>" ; $djlCart = $this->getDejalaCart($cart->id); if (isset($djlCart->delivery_price) && $cart->date_upd <= $djlCart->cart_date_upd && isset($djlCart->product)) { if ($productId >= 0 && $djlCart->product["id"] == $productId) { return $djlCart->product; } } $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; } $address = new Address($cart->id_address_delivery); // ask dejala.com 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"] = 10; $quotation["weight"] = (double) $cart->getTotalWeight(); $quotation["price"] = $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING); $quotation["module_version"] = $this->internal_version; $quotation["platform"] = "PS " . _PS_VERSION_; $this->mylog("asking for quotation=" . $this->logValue($quotation, 1)); $products = array(); $responseArray = $djlUtil->getStoreQuotation($this->dejalaConfig, $quotation, $products); if ($responseArray['status'] != '200') { return $shipping_cost; } $this->mylog("found quotation=" . $this->logValue($responseArray['response'], 1)); $electedProduct = NULL; foreach ($products as $key => $product) { if (is_null($electedProduct) || (int) $electedProduct['priority'] > (int) $key) { $electedProduct = $product; } } if (is_null($electedProduct)) { return $shipping_cost; } $djlCart->id_dejala_product = (int) $electedProduct["id"]; $djlCart->id_delivery = NULL; $djlCart->mode = $this->dejalaConfig->mode; $vat_factor = 1 + $electedProduct['vat'] / 100; $priceTTC = round($electedProduct['price'] * $vat_factor + $electedProduct['margin'], 2); $priceHT = round($priceTTC / $vat_factor, 2); $djlCart->delivery_price = $priceHT; $djlCart->cart_date_upd = $cart->date_upd; $djlCart->product = $electedProduct; $djlCart->save(); return $electedProduct; }
public function hookPDFInvoice($params) { if (!$this->useAlphaPDFInvoicePatcher) { return; } $order = new Order($params['id_order']); $djlCart = new DejalaCart($order->id_cart); if (Validate::isLoadedObject($djlCart) && isset($djlCart->id_dejala_product) && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) { $deliveryEndDate = ""; // TODO : Store the delivery timelimit in the dejalacart table at order time and use it here instead of querying something that might have changed. $djlUtil = new DejalaUtils(); $responseArray = $djlUtil->getStoreProductByID($this->dejalaConfig, $djlCart->id_dejala_product, $products); if ('200' == $responseArray['status'] && is_array($products)) { $deliveryEndDate = date('H\\h', $djlCart->shipping_date + (int) $products['timelimit'] * 3600); } $params['pdf']->pages[1] = str_replace($this->name . ")", $this->name . " \\(" . date('d/m/Y', $djlCart->shipping_date) . ', ' . date('H\\h', $djlCart->shipping_date) . "-" . $deliveryEndDate . "\\))", $params['pdf']->pages[1]); } }
public function placeOrder($mOrder) { $orderID = $mOrder->id; $this->myLog("placeOrder()"); $this->myLog("mOrder->id_carrier=" . $mOrder->id_carrier); $mCarrier = new Carrier($mOrder->id_carrier); $this->myLog("mCarrier->name=" . $mCarrier->name); if ($mCarrier->name != $this->name) { return; } $this->myLog("placeOrder()"); $id_cart = $mOrder->id_cart; $djlCart = new DejalaCart($id_cart); $this->myLog("djlCart->id_delivery=" . $djlCart->id_delivery); if (!$djlCart->id_delivery) { $this->myLog("id_delivery is not filled"); $delivery = array(); $this->getInfoFromOrder($orderID, $delivery); $this->mylog("Sending delivery=" . $this->logValue($delivery)); $djlUtil = new DejalaUtils(); $response = $djlUtil->orderDelivery($this->dejalaConfig, $delivery, $djlCart->mode); $statusCode = $response['status']; $this->mylog("send orderID=" . $orderID); $this->mylog("sendOrder status_code=" . $statusCode); $this->mylog("sendOrder response=" . $response['response']); $this->mylog("sendOrder delivery=" . $this->logValue($delivery, 1)); // update status after sending... if ("201" === $statusCode) { $this->mylog("updating dejala cart cart_id=" . $id_cart); if (Validate::isUnsignedId($delivery['id'])) { $this->mylog("updating dejala cart id_delivery=" . $delivery['id']); $djlCart->id_delivery = $delivery['id']; $djlCart->update(); } if (is_null($mOrder->shipping_number) || 0 === strlen($mOrder->shipping_number)) { $this->myLog('setting Order->shipping_number to ' . $delivery['tracking_number']); $mOrder->shipping_number = $delivery['tracking_number']; $mOrder->save(); } $this->myLog("OK - Order sent to dejala.fr"); } else { // Do nothing : Keep previous status $this->myLog("NOK - Problem sending Order to dejala.fr"); } } }