Descargar la presentación
La descarga está en progreso. Por favor, espere
1
COD ¿Qué queremos hacer?
Incluir un porcentaje de recargo para el pago “contra reembolso” Incluir una cantidad fija de recargo para el pago “contra reembolso” Asignar un producto al recargo Opcionalmente: Podemos incluir una variable que nos ponga un techo al importe del carrito para aplicar el recargo
2
COD ¿Dónde lo hacemos? Clase principal del módulo
Controlador para validar el carrito Template (views) 2
3
COD ¿Dónde lo hacemos? (cont.) Clase principal del módulo
- Instalación ( install() ) - Desinstalación ( uninstall()) - Constructor ( __ construct() ) - Formulario de configuración ( getContent () ) - Hook... ( payment ) 3
4
Instalación ( install() )
COD Instalación ( install() ) public function install() { // mod Configuration::updateValue('COD_PORCENT_FEE', 0); Configuration::updateValue ('COD_FIXED_FEE', 0); Configuration::updateValue ('COD_IDPRODUCT_FEE', 0); // Configuration::updateValue ('COD_MAX_ORDER_AMOUNT', 0); // end mod if (!parent::install () OR !$this->registerHook('payment') OR ! $this->registerHook('displayPaymentEU') OR !$this->registerHook('paymentReturn')) return false; return true; } 4
5
Desinstalación( uninstall() )
COD Desinstalación( uninstall() ) public function uninstall() { ¿ if (!Configuration::deleteByName('...') || !Configuration::deleteByName('...') ||! parent::uninstall()) return false; return true; ? } 5
6
Constructor ( __ construct() )
COD Constructor ( __ construct() ) public function __ construct() { … if ( ! (int) Configuration::get ( 'COD_IDPRODUCT_FEE' ) ) $this->warning = $this->l('You must assign a product to the fee!!!'); } 6
7
Formulario de configuración ( getContent () )
COD Formulario de configuración ( getContent () ) public function getContent() { /** * If values have been submitted in the form, process. */ if (((bool)Tools ::isSubmit('submitCODModule')) == true) { $this->postProcess(); } $this->context->smarty->assign( 'module_dir', $this->_path ); $output = ''; // You can add a tpl file or some html code return $output.$this->renderForm(); } 7
8
Procesar el Formulario ( postProcess () )
COD Procesar el Formulario ( postProcess () ) public function postProcess () { $form_values = $this->getConfigFormValues(); foreach (array_keys($form_values) as $key) { Configuration::updateValue($key, Tools::getValue($key)); } } 8
9
Formulario de configuración ( getContent () )
COD Formulario de configuración ( getContent () ) protected function renderForm() { $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = $ this->identifier; $helper->submit_action = 'submitCODModule'; … } 9
10
Formulario de configuración ( getContent () )
COD Formulario de configuración ( getContent () ) protected function renderForm() { ... $helper->currentIndex = $ this->context->link->getAdminLink('AdminModules', false) .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars= array( 'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */ 'languages' =>$this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ); return $helper->generateForm(array($ this->getConfigForm())); } 10
11
Formulario de configuración ( getContent () )
COD Formulario de configuración ( getContent () ) protected function getConfigForm() { return array( 'form' => array( 'legend' => array( 'title' => $this->l('Settings'), 'icon' => 'icon-cogs', ), 'input' => array( array( ... 11
12
Formulario de configuración ( getContent () )
COD Formulario de configuración ( getContent () ) protected function getConfigForm() { … 'input' => array( array( 'type' => 'text', 'prefix' => '<i class="icon icon-cogs"></i>', 'label' => $this->l('Fee Porcent'), 'name' => 'COD_PORCENT_FEE', 'desc' => $this->l('Assign a porcent value to calculate the fee'), ), ... 12
13
Formulario de configuración ( getContent () )
COD Formulario de configuración ( getContent () ) protected function getConfigForm() { … array( 'type' => 'text', 'prefix' => '<i class="icon icon-cogs"></i>', 'label' => $this->l('Fee Fixed Amount'), 'name' => 'COD_FIXED_FEE', 'desc ' => $this->l('Assign a fixed value to calculate the fee'), ), … 13
14
Formulario de configuración ( getContent () )
COD Formulario de configuración ( getContent () ) protected function getConfigForm() { … array( 'type' => 'text', 'prefix' => '<i class="icon icon-cogs"></i>', 'label' => $this->l('ID Product Fee'), 'name' => 'COD_IDPRODUCT_FEE', 'desc' => $this->l('Assign a product to the fee'), ), … 14
15
Formulario de configuración ( getContent () )
COD Formulario de configuración ( getContent () ) protected function getConfigForm() { … ), 'submit' =>array ( 'title' => $this->l('Save'), ), ), ); } .../ modules/modulename/views/templates/admin/_configure/helpers/form/form.tpl 15
16
COD Hook... ( payment ) public function hookPayment($params) {
{ if (!$this->active) return ; global $smarty; // Check if cart has product download if ($this->hasProductDownload($params['cart'])) return false; // mod … 16
17
COD Hook... ( payment ) Public function hookPayment($params) { ...
{ ... // mod $cod_content = array('fee' => 0, 'porcent_fee' =>0, 'fixed_fee' => 0); $fee = 0; if ((int)Configuration::get('COD_IDPRODUCT_FEE') > 0) { $cart = $this->context->cart; $cart_details = $cart->getSummaryDetails(null, true); $idproduct_fee = (int)Configuration::get('COD_IDPRODUCT_FEE'); $porcent_fee = (float)Configuration::get('COD_PORCENT_FEE'); 17
18
COD Hook... ( payment ) public function hookPayment($params) { ...
{ ... $fixed_fee = (float)Configuration::get('COD_FIXED_FEE'); $p = new Product($idproduct_fee); $vat = ($p->getTaxesRate()/100); $fee = 0; if($porcent_fee > 0) { $fee = number_format(( $cart_details['total_price'] * $porcent_fee ) / 100, 2, '.', '' ); ... 18
19
COD Hook... ( payment ) public function hookPayment($params) { ...
{ ... if ($fixed_fee >0) { $fee += $fixed_fee ; } } else if ($fixed_fee >0) { $fee =$fixedfee; } ... 19
20
COD Hook... ( payment ) public function hookPayment($params) { …
{ … if ((int)Configuration::get('COD_IDPRODUCT_FEE') > 0) { ... $fee = number_format ($fee,2,'.',''); $cod_content['fee'] = $fee; $cod_content['porcent_fee'] = $porcent_fee; $cod_content['fixed_fee'] = $fixed_fee; } // end mod … 20
21
COD Hook... ( payment ) public function hookPayment($params) { ...
{ ... $smarty->assign(array ( 'cod_content' => $cod_content, // by cpm 'this_path' => $this->_path , //keep for retro compat 'this_path_cod' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/' )); return $this->display(__FILE__, 'payment.tpl'); } 21
22
Controlador para validar el carrito
COD Controlador para validar el carrito Validación: Debemos cambiar el total del carrito, tambien podemos incluir más información si queremos. public function initContent() { parent::initContent(); $total = floatval($this->calcFee()) + floatval($this->context->cart->getOrderTotal(true, Cart::BOTH)); $this->context->smarty->assign(array( 'total' => $total, 'this_path' => $this->module->getPathUri(), // keep for retro compat 'this_path_cod' => $this->module->getPathUri(), 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/' .$ this->module->name.'/' )); $this->setTemplate('validation.tpl'); } 22
23
Controlador para validar el carrito
COD Controlador para validar el carrito Validación: Debemos cambiar el total del carrito, tambien podemos incluir más información si queremos. (Cont.) La función calcFee(), va a ser algo muy parecido a lo que ya hemos utilizado en la clase del módulo public function calcFee() { $fee = 0; if ((int)Configuration::get('COD_IDPRODUCT_FEE') > 0) { $cart = $this->context->cart; $cart_details = $cart->getSummaryDetails(null, true); $idproduct_fee = (int)Configuration::get('COD_IDPRODUCT_FEE'); $porcent_fee = Configuration::get('COD_PORCENT_FEE'); $fixed_fee = Configuration::get('COD_FIXED_FEE'); $p = new Product($idproduct_fee); $vat = ($p->getTaxesRate()/100); if ($porcent_fee > 0) { $fee = number_format( ( $cart_details['total_price'] * $porcent_fee ) / 100, 2, '.', '' ); …. ... if ($fixed_fee > 0) { $fee += $fixed_fee; } } else if ($fixed_fee > 0) { $fee = $fixedfee; $fee=number_format($fee,2,'.',''); } return $fee; } 23
24
Controlador para validar el carrito
COD Controlador para validar el carrito PostProcess: Debemos incluir el producto para el recargo, justo antes de pasar el carrito a pedido. public function postProcess() { ... if (Tools::getValue('confirm')) { $customer = new Customer((int)$this->context->cart->id_customer); $fee= floatval($this->calcFee()); $idproduct_fee = (int)Configuration::get('COD_IDPRODUCT_FEE'); $total = $fee + floatval($this->context->cart->getOrderTotal(true, Cart::BOTH));orig: $total = $this->context->cart->getOrderTotal(true, Cart::BOTH); $p=new Product($idproduct_fee); $iva=1+($p->getTaxesRate()/100); $p->price=number_format($fee/$iva,2,'.',''); $p->updateWs(); $cart->updateQty(1,$idproduct_fee); $cart->getPackageList(true); $this->module->validateOrder((int)$this->context->cart->id, Configuration::get('PS_OS_PREPARATION'), $total, $this->module->displayName, null, array(), null, false, $customer->secure_key); …. } 24
25
COD Podemos ampliar nuestro módulo y mejorarlo
- Selección/creación del produccto para recargo $p = new Product; $p->name = $name; $p->id_category_default = $cats[0]; * $p->category = $cats[0]; * $p->id_tax_rules_group = 0; $p->available_for_order = 1; $p->visibility = 'both'; $p->active =0; - Comprobar que tenemos un producto para recargo y que el producto existe if ( $p = new Product ( $ id ) ) - Comprobar el carrito, o comprobar que el recargo es positivo( > 0) if ( isnull ( $this->context->cart ) ) $this->context->cart=new Cart($context->cookie->id_cart); 25
Presentaciones similares
© 2025 SlidePlayer.es Inc.
All rights reserved.