Skip to content

Commit

Permalink
Update v1.1.4
Browse files Browse the repository at this point in the history
* Fixed a bug when a decimal value in the "total cart value" condition's field wasn't valid.
* Fixed a bug with cart summary not shown correctly on some earlier Prestashop 1.7 versions.
* Taxes are displayed correctly in cart summary on Prestashop 1.7
* Improved compatibility with various Prestashop versions when adding the fee to carrier's fee.
* When reordering an order with COD Product, it will be deleted from the cart automatically (except for some early 1.7 PS versions).
  • Loading branch information
sakgiok committed Feb 7, 2019
1 parent 5ac55f7 commit aa9ed86
Show file tree
Hide file tree
Showing 19 changed files with 7,636 additions and 1,377 deletions.
6 changes: 6 additions & 0 deletions codwfeeplus changelog.md
@@ -1,3 +1,9 @@
## v1.1.4
* Fixed a bug when a decimal value in the "total cart value" condition's field wasn't valid.
* Fixed a bug with cart summary not shown correctly on some earlier Prestashop 1.7 versions.
* Taxes are displayed correctly in cart summary on Prestashop 1.7
* Improved compatibility with various Prestashop versions when adding the fee to carrier's fee.
* When reordering an order with COD Product, it will be deleted from the cart automatically (except for some early 1.7 PS versions).
## v1.1.3
* Fixed a serious bug in payment validation.
## v1.1.2
Expand Down
1,371 changes: 37 additions & 1,334 deletions codwfeeplus/codwfeeplus.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion codwfeeplus/config.xml
Expand Up @@ -2,7 +2,7 @@
<module>
<name>codwfeeplus</name>
<displayName><![CDATA[Cash on delivery with fee (COD) PLUS]]></displayName>
<version><![CDATA[1.1.3]]></version>
<version><![CDATA[1.1.4]]></version>
<description><![CDATA[Accept cash on delivery payments with extra fee and more options]]></description>
<author><![CDATA[Sakis Gkiokas]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
58 changes: 38 additions & 20 deletions codwfeeplus/controllers/admin/AdminCODwFeePlusController.php
Expand Up @@ -29,6 +29,7 @@
class AdminCODwFeePlusController extends ModuleAdminController
{

public static $definition = array();
private $_html = '';
private $_errors = array();
private $_msg = array();
Expand Down Expand Up @@ -61,7 +62,7 @@ class AdminCODwFeePlusController extends ModuleAdminController
array('name' => 'CODWFEEPLUS_MIN', 'type' => 'Price', 'out' => 'minimum cart value', 'multilang' => 0, 'req' => 0),
array('name' => 'CODWFEEPLUS_MAX', 'type' => 'Price', 'out' => 'maximum cart value', 'multilang' => 0, 'req' => 0),
array('name' => 'CODWFEEPLUS_CARTVALUE_SIGN', 'type' => 'Int', 'out' => 'cart value comparison', 'multilang' => 0, 'req' => 0),
array('name' => 'CODWFEEPLUS_CARTVALUE', 'type' => 'Int', 'out' => 'cart value', 'multilang' => 0, 'req' => 0),
array('name' => 'CODWFEEPLUS_CARTVALUE', 'type' => 'Price', 'out' => 'cart value', 'multilang' => 0, 'req' => 0),
array('name' => 'CODWFEEPLUS_CARTVALUE_INCLUDE_CARRIER', 'type' => 'Int', 'out' => 'cart value include carrier', 'multilang' => 0, 'req' => 0),
array('name' => 'CODWFEEPLUS_DELIVERY_ARRAY', 'type' => 'ArrayWithIds', 'out' => 'carriers', 'multilang' => 0, 'req' => 0),
array('name' => 'CODWFEEPLUS_COUNTRIES_ARRAY', 'type' => 'ArrayWithIds', 'out' => 'countries', 'multilang' => 0, 'req' => 0),
Expand Down Expand Up @@ -210,8 +211,6 @@ private function renderTestResult()
public function renderView()
{
$this->_html = '';
$this->context->controller->addCSS($this->path . 'views/css/style-admin.css');
$this->context->controller->addJS($this->path . 'views/js/admin.js');

if (!$this->module->active) {
$this->_html .= $this->renderModuleInactiveWarning('all');
Expand Down Expand Up @@ -255,6 +254,9 @@ public function renderView()

public function postProcess()
{
$this->context->controller->addCSS($this->path . 'views/css/style-admin.css');
$this->context->controller->addJS($this->path . 'views/js/admin.js');

$this->_errors = array();
$this->_msg = array();
$this->_condForm_id = null;
Expand Down Expand Up @@ -308,6 +310,7 @@ public function postProcess()
} elseif (isset($this->context->cookie->{$this->list_id . '_start'})) {
unset($this->context->cookie->{$this->list_id . '_start'});
}
$this->className = get_class($this);
$this->processFilter();
$this->_display_mode = 'view_log';
if (Tools::isSubmit('submitResetcodwfeeplus_transactions')) {
Expand Down Expand Up @@ -962,13 +965,17 @@ public function renderTestForm($hide = true)
$tree = new HelperTreeCategories('codwfeeplus_test_cat_tree');
$tree->setUseCheckBox(true)
->setUseSearch(false)
->setIdTree('codwfeeplus_test_cat_tree')
->setFullTree(true)
->setChildrenOnly(true)
->setNoJS(true)
->setRootCategory($root_category)
->setInputName('test_categoryBox')
->setSelectedCategories($test_field_values['tstfrm_category']);
if (Tools::version_compare(_PS_VERSION_, '1.6.1.0', '>')) {
$tree->setIdTree('codwfeeplus_test_cat_tree');
}
if (Tools::version_compare(_PS_VERSION_, '1.6.0.9', '>')) {
$tree->setFullTree(true);
$tree->setChildrenOnly(true);
$tree->setNoJS(false);
}
$categoryTree = $tree->render();
//token changed because of the category tree... So change it back.
$this->context->smarty->assign('token', $this->token);
Expand Down Expand Up @@ -1402,8 +1409,10 @@ protected function renderOrderList()

$values = $this->getOrderListValues();
$helper->listTotal = $this->_listTotal;
$helper->_default_pagination = $this->_default_pagination;
$helper->_pagination = $this->_pagination;
if (Tools::version_compare(_PS_VERSION_, '1.6.0.9', '>')) {
$helper->_default_pagination = $this->_default_pagination;
$helper->_pagination = $this->_pagination;
}
$helper->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
Expand Down Expand Up @@ -1650,8 +1659,10 @@ protected function renderConditionsList()
}
$values = $this->getConditionListValues();
$helper->listTotal = count($values);
$helper->_default_pagination = 10000;
$helper->_pagination = array(10000);
if (Tools::version_compare(_PS_VERSION_, '1.6.0.9', '>')) {
$helper->_default_pagination = 10000;
$helper->_pagination = array(10000);
}
$helper->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
Expand Down Expand Up @@ -1702,6 +1713,10 @@ protected function renderConditionsList()
'icon' => 'icon-list',
);

if (Tools::version_compare(_PS_VERSION_, '1.6.1.0', '<=')) {
$helper->tpl_vars['filters_has_value'] = false;
}

$helper->toolbar_btn['new'] = array(
'href' => $this->context->link->getAdminLink('AdminCODwFeePlus', false)
. '&submitCODwFeePlus_add=1&token=' . Tools::getAdminTokenLite('AdminCODwFeePlus'),
Expand Down Expand Up @@ -2054,7 +2069,6 @@ public function getConditionList()
//FORM
public function renderFormConditions($in_cond_id = null, $getfrompost = false)
{
// $this->addJS(_PS_BO_ALL_THEMES_DIR_ . 'default/js/tree.js');
$carriers = Carrier::getCarriers($this->context->language->id, false, false, false, null, Carrier::ALL_CARRIERS);
$carriers_list = array();
foreach ($carriers as $value) {
Expand Down Expand Up @@ -2205,13 +2219,17 @@ public function renderFormConditions($in_cond_id = null, $getfrompost = false)
$tree = new HelperTreeCategories('codwfeeplus_cat_tree');
$tree->setUseCheckBox(true)
->setUseSearch(false)
->setIdTree('codwfeeplus_cond_cat_tree')
->setFullTree(true)
->setChildrenOnly(true)
->setNoJS(true)
->setRootCategory($category)
->setInputName('cond_categoryBox')
->setSelectedCategories($fieldValues['categories']);
if (Tools::version_compare(_PS_VERSION_, '1.6.1.0', '>')) {
$tree->setIdTree('codwfeeplus_cond_cat_tree');
}
if (Tools::version_compare(_PS_VERSION_, '1.6.0.9', '>')) {
$tree->setFullTree(true);
$tree->setChildrenOnly(true);
$tree->setNoJS(false);
}
$categoryTree = $tree->render();
//token changed because of the category tree... So change it back.
$this->context->smarty->assign('token', $this->token);
Expand Down Expand Up @@ -3264,18 +3282,18 @@ private function areThereOtherShops()
public function getContrastColor($hexColor)
{

//////////// hexColor RGB
//////////// hexColor RGB
$R1 = hexdec(substr($hexColor, 1, 2));
$G1 = hexdec(substr($hexColor, 3, 2));
$B1 = hexdec(substr($hexColor, 5, 2));

//////////// Black RGB
//////////// Black RGB
$blackColor = "#000000";
$R2BlackColor = hexdec(substr($blackColor, 1, 2));
$G2BlackColor = hexdec(substr($blackColor, 3, 2));
$B2BlackColor = hexdec(substr($blackColor, 5, 2));

//////////// Calc contrast ratio
//////////// Calc contrast ratio
$L1 = 0.2126 * pow($R1 / 255, 2.2) +
0.7152 * pow($G1 / 255, 2.2) +
0.0722 * pow($B1 / 255, 2.2);
Expand All @@ -3291,7 +3309,7 @@ public function getContrastColor($hexColor)
$contrastRatio = (int) (($L2 + 0.05) / ($L1 + 0.05));
}

//////////// If contrast is more than 5, return black color
//////////// If contrast is more than 5, return black color
if ($contrastRatio > 5) {
return '#000000';
} else { //////////// if not, return white color.
Expand Down
46 changes: 32 additions & 14 deletions codwfeeplus/controllers/front/ajax.php
Expand Up @@ -40,34 +40,52 @@ public function postProcess()
);

if ($cod_active) {
$taxconfiguration = new TaxConfiguration();
$include_taxes = $taxconfiguration->includeTaxes();
$cart_obj = $this->context->cart;
$address_id = $cart_obj->getTaxAddressId();
$address_id = 0;

$taxAddressType = Configuration::get('PS_TAX_ADDRESS_TYPE');
if (Validate::isLoadedObject($cart_obj) && !empty($taxAddressType)) {
$address_id = $cart_obj->$taxAddressType;
} else {
$address_id = $cart_obj->id_address_delivery;
}

$CODfee = $this->module->getCostFromCart($this->context->cart);

$CODfee_tax = $this->module->getCODFeeTax($cart_obj->id_carrier, $address_id);

$CODfee_notax = Tools::ps_round(((float) $CODfee) / (1.0 + $CODfee_tax), 9);
$CODfee_tax_amount = Tools::ps_round(((float) $CODfee_notax) * $CODfee_tax, 9);
$total_cart = $this->context->cart->getOrderTotal(true, Cart::BOTH);
$total_cart_notax = $this->context->cart->getOrderTotal(false, Cart::BOTH);

$CODFee_final = $CODfee;
if (!$include_taxes) {
$CODFee_final = $CODfee_notax;
}

if (isset($cart['subtotals']['tax'])) {
$total_taxes = $total_cart - $total_cart_notax;
$cart['subtotals']['tax']['amount'] = $total_taxes + $CODfee_tax_amount;
$cart['subtotals']['tax']['value'] = Tools::displayPrice($total_taxes + $CODfee_tax_amount);
$cart['subtotals']['tax']['amount'] += $CODfee_tax_amount;
$cart['subtotals']['tax']['value'] = Tools::displayPrice($cart['subtotals']['tax']['amount']);
}
$cart['subtotals']['cod'] = array(
'amount' => $CODfee,
'amount' => $CODFee_final,
'label' => $this->module->l('Cash on delivery fee', 'ajax'),
'type' => 'cod_fee',
'value' => Tools::displayPrice($CODfee),
'value' => Tools::displayPrice($CODFee_final),
);
$cart['totals']['total']['amount'] = $total_cart + $CODfee;
$cart['totals']['total']['value'] = Tools::displayPrice($total_cart + $CODfee);
$cart['totals']['total_excluding_tax']['amount'] = $total_cart_notax + $CODfee_notax;
$cart['totals']['total_excluding_tax']['value'] = Tools::displayPrice($total_cart_notax + $CODfee_notax);
$cart['totals']['total_including_tax']['amount'] = $total_cart + $CODfee;
$cart['totals']['total_including_tax']['value'] = Tools::displayPrice($total_cart + $CODfee);
if (isset($cart['totals']['total']['amount'])) {
$cart['totals']['total']['amount'] += $CODFee_final;
$cart['totals']['total']['value'] = Tools::displayPrice($cart['totals']['total']['amount']);
}
if (isset($cart['totals']['total_excluding_tax']['amount'])) {
$cart['totals']['total_excluding_tax']['amount'] += $CODfee_notax;
$cart['totals']['total_excluding_tax']['value'] = Tools::displayPrice($cart['totals']['total_excluding_tax']['amount']);
}
if (isset($cart['totals']['total_including_tax']['amount'])) {
$cart['totals']['total_including_tax']['amount'] += $CODfee;
$cart['totals']['total_including_tax']['value'] = Tools::displayPrice($cart['totals']['total_including_tax']['amount']);
}
}

ob_end_clean();
Expand Down
8 changes: 3 additions & 5 deletions codwfeeplus/controllers/front/validation.php
Expand Up @@ -20,6 +20,7 @@
* @copyright 2018 Sakis Gkiokas
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
*/

class CODwFeePlusValidationModuleFrontController extends ModuleFrontController
{

Expand Down Expand Up @@ -96,11 +97,8 @@ private function validate_addToCarrier($CODfee, $cart, $customer, $orderstate)
{
$currency = $this->context->currency;
$total = ($cart->getOrderTotal(true, Cart::BOTH) + $CODfee);
if ($this->module->is17) {
$this->module->validateOrder_AddToCarrier_17($CODfee, (int) $cart->id, $orderstate, $total, $this->module->public_name, null, array(), (int) $currency->id, false, $customer->secure_key);
} else {
$this->module->validateOrder_AddToCarrier_16($CODfee, (int) $cart->id, $orderstate, $total, $this->module->public_name, null, array(), (int) $currency->id, false, $customer->secure_key);
}

$this->module->runCorrect_validateOrder($CODfee, (int) $cart->id, $orderstate, $total, $this->module->public_name, null, array(), (int) $currency->id, false, $customer->secure_key);
}

/**
Expand Down

0 comments on commit aa9ed86

Please sign in to comment.