Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
luciobenini committed Oct 22, 2021
0 parents commit 202680b
Show file tree
Hide file tree
Showing 28 changed files with 1,228 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Private files
# The following files contain your database credentials and other personal data.

config/settings.*.php

# Cache, temp and generated files
# The following files are generated by PrestaShop.

admin-dev/autoupgrade/
/cache/*
!/cache/index.php
!/cache/*/
/cache/*/*
!/cache/cachefs/index.php
!/cache/purifier/index.php
!/cache/push/index.php
!/cache/sandbox/index.php
!/cache/smarty/index.php
!/cache/tcpdf/index.php
config/xml/*.xml
/log/*
*sitemap.xml
themes/*/cache/
modules/*/config*.xml
config*.xml

# Site content
# The following folders contain product images, virtual products, CSV's, etc.

admin-dev/backups/
admin-dev/export/
admin-dev/import/
download/
/img/*
upload/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Lucio Benini

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# pittica/prestashop-codfee

![License](https://img.shields.io/github/license/pittica/prestashop-codfee)
![Release](https://img.shields.io/github/v/release/pittica/prestashop-codfee)

COD fees for [PrestaShop](https://github.com/prestashop/prestashop).

Based on ps_wirepayment module by [PrestaShop](https://github.com/prestashop/prestashop).

## Requirements

[PrestaShop](https://github.com/prestashop/prestashop) version 1.7 or newer.

## Copyright

(c) 2021, [Pittica S.r.l.](https://pittica.com).
120 changes: 120 additions & 0 deletions classes/CodFee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

/**
* PrestaShop Module - pitticacodfee
*
* Copyright 2021 Pittica S.r.l.
*
* @category Module
* @package Pittica/PrestaShop/CodFee
* @author Lucio Benini <[email protected]>
* @copyright 2021 Pittica S.r.l.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-codfee
*/

/**
* Fee object model.
*
* @category ObjectModel
* @package Pittica/PrestaShop/CodFee
* @author Lucio Benini <[email protected]>
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-codfee/blob/main/classes/CodFee.php
* @since 1.0.0
*/
class CodFee extends ObjectModel
{
const TABLE_NAME = 'pittica_codfee_fee';

/**
* {@inheritDoc}
*
* @var boolean
*/
public $force_id = true;

public $fee;
public $limit;
public $active;

/**
* {@inheritDoc}
*
* @var array
*/
public static $definition = array(
'table' => self::TABLE_NAME,
'primary' => 'id_carrier',
'multilang' => false,
'multishop' => true,
'fields' => array(
'fee' => array(
'type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => false
),
'limit' => array(
'type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => false
),
'active' => array(
'type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => false
)
)
);

/**
* Gets the prices including taxes.
*
* @return float
* @since 1.0.0
*/
public function getPrice()
{
return $this->fee ? $this->fee * (1 + ((float) Tax::getCarrierTaxRate($this->id) / 100)) : 0;
}

/**
* Determines whether the C.O.D. is valid.
*
* @param Cart $cart The cart to check.
*
* @return boolean
* @since 1.0.0
*/
public function isValid($cart)
{
if ($this->active) {
return (!$this->limit || ($cart->getOrderTotal(true, Cart::BOTH) + $this->getPrice()) < $this->limit) && !$cart->isVirtualCart();
}

return false;
}

/**
* Gets the fees.
*
* @return array
* @since 1.0.0
*/
public static function getFees()
{
$result = Db::getInstance()->executeS('SELECT o.* FROM `' . _DB_PREFIX_ . self::TABLE_NAME . '` o');
$fees = array();

foreach ($result as $row) {
$fees[$row['id_carrier']] = $row;
}

return $fees;
}

/**
* Truncates the table.
*
* @return boolean
* @since 1.0.0
*/
public static function truncate()
{
return Db::getInstance()->execute('TRUNCATE `' . _DB_PREFIX_ . self::TABLE_NAME . '`');
}
}
24 changes: 24 additions & 0 deletions classes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* PrestaShop Module - pitticacodfee
*
* Copyright 2021 Pittica S.r.l.
*
* @category Module
* @package Pittica/PrestaShop/CodFee
* @author Lucio Benini <[email protected]>
* @copyright 2021 Pittica S.r.l.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-codfee
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
24 changes: 24 additions & 0 deletions controllers/front/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* PrestaShop Module - pitticacodfee
*
* Copyright 2021 Pittica S.r.l.
*
* @category Module
* @package Pittica/PrestaShop/CodFee
* @author Lucio Benini <[email protected]>
* @copyright 2021 Pittica S.r.l.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-codfee
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
86 changes: 86 additions & 0 deletions controllers/front/validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/**
* PrestaShop Module - pitticacodfee
*
* Copyright 2021 Pittica S.r.l.
*
* @category Module
* @package Pittica/PrestaShop/CodFee
* @author Lucio Benini <[email protected]>
* @copyright 2021 Pittica S.r.l.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-codfee
*/

require_once dirname(__FILE__) . '../../../classes/CodFee.php';

/**
* Validation front controller.
*
* @category Controller
* @package Pittica/PrestaShop/CodFee
* @author Lucio Benini <[email protected]>
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-codfee/blob/main/controllers/front/validation.php
* @since 1.0.0
*/
class pitticacodfeevalidationModuleFrontController extends ModuleFrontController
{
/**
* {@inheritDoc}
*
* @return void
* @since 1.0.0
*/
public function postProcess()
{
$cart = $this->context->cart;
$fee = new CodFee($cart->id_carrier);

if (!$fee->isValid($cart)) {
Tools::redirect($this->context->link->getPageLink('order', null, null, array(
'step' => '1'
)));
}

if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
Tools::redirect($this->context->link->getPageLink('order', null, null, array(
'step' => '1'
)));
}

$authorized = false;

foreach (Module::getPaymentModules() as $module) {
if ($module['name'] == 'pitticacodfee') {
$authorized = true;
break;
}
}

if (!$authorized) {
die($this->module->getTranslator()->l('This payment method is not available.'));
}

$customer = new Customer($cart->id_customer);

if (!Validate::isLoadedObject($customer)) {
Tools::redirect($this->context->link->getPageLink('order', null, null, array(
'step' => '1'
)));
}

$currency = $this->context->currency;
$total = (float) $cart->getOrderTotal(true, Cart::BOTH);

$this->module->validateOrder($cart->id, Configuration::get('PS_OS_PREPARATION'), $total, $this->module->l('C.O.D.'), null, array(), (int) $currency->id, false, $customer->secure_key);

Tools::redirect($this->context->link->getPageLink('order-confirmation', null, null, array(
'id_cart' => $cart->id,
'id_module' => $this->module->id,
'id_order' => $this->module->currentOrder,
'key' => $customer->secure_key
)));
}
}
24 changes: 24 additions & 0 deletions controllers/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* PrestaShop Module - pitticacodfee
*
* Copyright 2021 Pittica S.r.l.
*
* @category Module
* @package Pittica/PrestaShop/CodFee
* @author Lucio Benini <[email protected]>
* @copyright 2021 Pittica S.r.l.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-codfee
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
24 changes: 24 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* PrestaShop Module - pitticacodfee
*
* Copyright 2021 Pittica S.r.l.
*
* @category Module
* @package Pittica/PrestaShop/CodFee
* @author Lucio Benini <[email protected]>
* @copyright 2021 Pittica S.r.l.
* @license http://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0 ( LGPL-3.0 )
* @link https://github.com/pittica/prestashop-codfee
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions pitticacodfee.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
Loading

0 comments on commit 202680b

Please sign in to comment.