Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adiciona modulo de desconto e taxa na loja
- Loading branch information
1 parent
4a10355
commit 7edcc42
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
# Matches multiple files with brace expansion notation | ||
# Set default charset | ||
[*.php] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.twig] | ||
indent_size = 2 | ||
|
||
# 4 space indentation | ||
[*.json] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# Tab indentation (no size specified) | ||
[Makefile] | ||
indent_style = tab | ||
|
||
# Matches the exact files either package.json or .travis.yml | ||
[{package.json,.travis.yml}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
4 changes: 4 additions & 0 deletions
4
upload/catalog/language/en-gb/extension/total/pagseguro_discount.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
// Heading | ||
$_['heading_title'] = 'PagSeguro Desconto'; |
4 changes: 4 additions & 0 deletions
4
upload/catalog/language/en-gb/extension/total/pagseguro_fee.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
// Heading | ||
$_['heading_title'] = 'PagSeguro Taxa'; |
58 changes: 58 additions & 0 deletions
58
upload/catalog/model/extension/total/pagseguro_discount.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
class ModelExtensionTotalPagSeguroDiscount extends Model | ||
{ | ||
const EXTENSION_PAYMENT_PREFIX = 'payment_pagseguro_'; | ||
const EXTENSION_PAGSEGURO_BOLETO = self::EXTENSION_PAYMENT_PREFIX . 'boleto'; | ||
const EXTENSION_PAGSEGURO_CREDIT = self::EXTENSION_PAYMENT_PREFIX . 'credit'; | ||
const EXTENSION_PAGSEGURO_DEBIT = self::EXTENSION_PAYMENT_PREFIX . 'debit'; | ||
|
||
public function getTotal($total) { | ||
$status_key = self::EXTENSION_PAYMENT_PREFIX . 'status'; | ||
|
||
if ( | ||
isset($this->session->data['payment_method']) && | ||
$this->config->get($status_key) | ||
) { | ||
$this->load->language('extension/total/pagseguro_discount', 'pg-discount'); | ||
|
||
$discount_value = $this->getDiscountValue(); | ||
|
||
if ($discount_value > 0) { | ||
$discount_total = ($discount_value / 100) * $this->cart->getSubTotal(); | ||
|
||
$language = $this->language->get('pg-discount'); | ||
|
||
$total['totals'][] = array( | ||
'code' => 'pagseguro_discount', | ||
'title' => $language->get('heading_title'), | ||
'value' => -$discount_total, | ||
'sort_order' => $this->config->get('total_sub_total_sort_order') + 1 | ||
); | ||
|
||
$total['total'] -= $discount_total; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Captura o valor do desconto | ||
* | ||
* @return float | ||
*/ | ||
private function getDiscountValue(): float | ||
{ | ||
switch ($this->session->data['payment_method']) { | ||
case self::EXTENSION_PAGSEGURO_BOLETO: | ||
return floatval($this->config->get(self::EXTENSION_PAYMENT_PREFIX . 'discount_boleto')); | ||
break; | ||
case self::EXTENSION_PAGSEGURO_CREDIT: | ||
return floatval($this->config->get(self::EXTENSION_PAYMENT_PREFIX . 'discount_credit')); | ||
break; | ||
case self::EXTENSION_PAGSEGURO_DEBIT: | ||
return floatval($this->config->get(self::EXTENSION_PAYMENT_PREFIX . 'discount_debit')); | ||
default: | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
class ModelExtensionTotalPagSeguroFee extends Model | ||
{ | ||
const EXTENSION_PAYMENT_PREFIX = 'payment_pagseguro_'; | ||
const EXTENSION_PAGSEGURO_BOLETO = self::EXTENSION_PAYMENT_PREFIX . 'boleto'; | ||
const EXTENSION_PAGSEGURO_CREDIT = self::EXTENSION_PAYMENT_PREFIX . 'credit'; | ||
const EXTENSION_PAGSEGURO_DEBIT = self::EXTENSION_PAYMENT_PREFIX . 'debit'; | ||
|
||
public function getTotal($total) { | ||
$status_key = self::EXTENSION_PAYMENT_PREFIX . 'status'; | ||
|
||
if ( | ||
isset($this->session->data['payment_method']) && | ||
$this->config->get($status_key) | ||
) { | ||
$this->load->language('extension/total/pagseguro_fee', 'pg-fee'); | ||
|
||
$fee_value = $this->getFeeValue(); | ||
|
||
if ($fee_value > 0) { | ||
$fee_total = ($fee_value / 100) * $this->cart->getSubTotal(); | ||
|
||
$language = $this->language->get('pg-fee'); | ||
|
||
$total['totals'][] = array( | ||
'code' => 'pagseguro_fee', | ||
'title' => $language->get('heading_title'), | ||
'value' => $fee_total, | ||
'sort_order' => $this->config->get('total_sub_total_sort_order') + 1 | ||
); | ||
|
||
$total['total'] += $fee_total; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Captura o valor da taxa | ||
* | ||
* @return float | ||
*/ | ||
private function getFeeValue(): float | ||
{ | ||
switch ($this->session->data['payment_method']) { | ||
case self::EXTENSION_PAGSEGURO_BOLETO: | ||
return floatval($this->config->get(self::EXTENSION_PAYMENT_PREFIX . 'fee_boleto')); | ||
break; | ||
case self::EXTENSION_PAGSEGURO_CREDIT: | ||
return floatval($this->config->get(self::EXTENSION_PAYMENT_PREFIX . 'fee_credit')); | ||
break; | ||
case self::EXTENSION_PAGSEGURO_DEBIT: | ||
return floatval($this->config->get(self::EXTENSION_PAYMENT_PREFIX . 'fee_debit')); | ||
default: | ||
return 0; | ||
} | ||
} | ||
} |