diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..008d8ec --- /dev/null +++ b/.editorconfig @@ -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 + diff --git a/upload/catalog/language/en-gb/extension/total/pagseguro_discount.php b/upload/catalog/language/en-gb/extension/total/pagseguro_discount.php new file mode 100644 index 0000000..58d3ee6 --- /dev/null +++ b/upload/catalog/language/en-gb/extension/total/pagseguro_discount.php @@ -0,0 +1,4 @@ +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; + } + } +} diff --git a/upload/catalog/model/extension/total/pagseguro_fee.php b/upload/catalog/model/extension/total/pagseguro_fee.php new file mode 100644 index 0000000..7a48f2d --- /dev/null +++ b/upload/catalog/model/extension/total/pagseguro_fee.php @@ -0,0 +1,58 @@ +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; + } + } +}