コード例 #1
0
ファイル: seur.php プロジェクト: tomideru/PrestaShop-modules
    public function hookDisplayOrderConfirmation($params)
    {
        $carrier_pos = SeurLib::getSeurCarrier('SEP');
        if ($carrier_pos['id'] != (int) $params['objOrder']->id_carrier) {
            //check if COD carrier with pickup points
            return '';
        }
        if (Db::getInstance()->getValue('
			SELECT `id_address_delivery`
			FROM `' . _DB_PREFIX_ . 'seur_order`
			WHERE `id_order` = "' . (int) $params['objOrder']->id . '"
		')) {
            return;
        }
        $customer_address = new Address((int) $params['objOrder']->id_address_delivery);
        $pickup_point_info = SeurLib::getOrderPos((int) $params['objOrder']->id_cart);
        $pickup_point_address = new Address();
        $pickup_point_address->id_country = $customer_address->id_country;
        $pickup_point_address->id_state = $customer_address->id_state;
        $pickup_point_address->alias = $customer_address->alias;
        $pickup_point_address->company = urldecode($pickup_point_info['company']);
        $pickup_point_address->lastname = $customer_address->lastname;
        $pickup_point_address->firstname = $customer_address->firstname;
        $pickup_point_address->address1 = urldecode($pickup_point_info['address']);
        $pickup_point_address->postcode = urldecode($pickup_point_info['postal_code']);
        $pickup_point_address->city = urldecode($pickup_point_info['city']);
        $pickup_point_address->phone = $customer_address->phone_mobile ? $customer_address->phone_mobile : self::DEFAULT_PUDO_MOBILE;
        $order = new Order((int) $params['objOrder']->id);
        $products = $order->getProductsDetail();
        $order_weigth = 0;
        foreach ($products as $product) {
            $order_weigth += (double) $product['product_weight'] * (double) $product['product_quantity'];
        }
        $order_weigth = $order_weigth > 1 ? $order_weigth : 1;
        if ($pickup_point_address->save()) {
            $order->id_address_delivery = (int) $pickup_point_address->id;
            if ($order->save()) {
                Db::getInstance()->Execute('
					INSERT INTO `' . _DB_PREFIX_ . 'seur_order`
					VALUES ("' . (int) $order->id . '", "1", "' . (double) $order_weigth . '", null, "0", "0", "' . (int) $pickup_point_address->id . '");');
            } else {
                Db::getInstance()->Execute('
					INSERT INTO `' . _DB_PREFIX_ . 'seur_order`
					VALUES ("' . (int) $order->id . '", "1", "' . (double) $order_weigth . '", null, "0", "0", "");');
            }
        } else {
            Db::getInstance()->Execute('
				INSERT INTO `' . _DB_PREFIX_ . 'seur_order`
				VALUES ("' . (int) $order->id . '", "1", "' . (double) $order_weigth . '", null, "0", "0", "");');
        }
    }
コード例 #2
0
 public function hookPayment($params)
 {
     if (!$this->active || !SeurLib::getConfigurationField('seur_cod')) {
         // Cash on delivery is disabled in Seur Configuration
         return;
     }
     $address = new Address((int) $params['cart']->id_address_delivery);
     $country = new Country((int) $address->id_country);
     $seur_carrier_sen = SeurLib::getSeurCarrier('SEN');
     $seur_carrier_scn = SeurLib::getSeurCarrier('SCN');
     $seur_carrier_sce = SeurLib::getSeurCarrier('SCE');
     $cod_carriers = array($seur_carrier_scn['id'], $seur_carrier_sen['id'], $seur_carrier_sce['id']);
     if (($country->iso_code == 'ES' || $country->iso_code == 'PT' || $country->iso_code == 'AD') && in_array($params['cart']->id_carrier, $cod_carriers)) {
         $cost = (double) abs($params['cart']->getOrderTotal(true, Cart::BOTH));
         $cargo = number_format($this->getCargo($params['cart']), 2, '.', '');
         $total_con_cargo = (double) ($cost + $cargo);
         if (version_compare(_PS_VERSION_, "1.5", ">=")) {
             $this->context->smarty->assign(array('ruta' => $this->_path, 'coste' => $cost, 'cargo' => $cargo, 'total' => $total_con_cargo, 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/', 'enlace' => $this->context->link->getModuleLink('seurcashondelivery', 'validation', array(), true), 'visible' => 1));
             $id_carrier = "";
             $delivery_options_array = Tools::getValue('delivery_option');
             if (is_array($delivery_options_array)) {
                 foreach ($delivery_options_array as $id_carrier) {
                     if ($seur_carrier_scn['id'] == (int) $id_carrier || $seur_carrier_sen['id'] == (int) $id_carrier || $seur_carrier_sce['id'] == (int) $id_carrier) {
                         return $this->display(__FILE__, 'views/templates/hook/payment.tpl');
                     }
                 }
             }
             if ($id_carrier == "") {
                 if (in_array(Configuration::get('PS_CARRIER_DEFAULT'), $cod_carriers)) {
                     return $this->display(__FILE__, 'views/templates/hook/payment.tpl');
                 } else {
                     $this->context->smarty->assign('visible', 0);
                     return $this->display(__FILE__, 'views/templates/hook/payment.tpl');
                 }
             }
         } else {
             $smarty = $this->context->smarty;
             $url = $this->getModuleLink('seurcashondelivery', 'payment.php');
             $smarty->assign(array('ruta' => $this->_path, 'coste' => $cost, 'cargo' => $cargo, 'total' => $total_con_cargo, 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/', 'enlace' => $url, 'visible' => 1));
             if (in_array(Tools::getValue('id_carrier'), $cod_carriers)) {
                 return $this->display($this->path, 'views/templates/hook/payment.tpl');
             } else {
                 $this->context->smarty->assign('visible', 0);
                 return $this->display($this->path, 'views/templates/hook/payment.tpl');
             }
         }
     }
     return '';
 }