示例#1
0
 /**
  * Save information to enable delivery to be ordered after payment
  */
 public function hookCart($param)
 {
     $this->hooklog("hookCart", "");
     $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[] = 'An error occured while getting product';
         } else {
             if (isset($product['timelimit'])) {
                 $timelimit = intval($product['timelimit']);
             } else {
                 $timelimit = 3;
             }
             /* 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() - 300) {
                     $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;
             // MFR090202 - Fix SQL injection possibility following Rémi Gaillard remarks
             $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);
         }
     }
 }
示例#2
0
 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]);
     }
 }
示例#3
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);
         }
     }
 }