Skip to content

Commit

Permalink
Corrige validação de quantidade de parcelas no checkout (#115)
Browse files Browse the repository at this point in the history
* Remove parcelas do checkout se o parcelamento estiver desabilitado

* Insere testes

* Insere ID no seletor de parcelas do checkout

* Versão 1.8.2
  • Loading branch information
laerte-guimaraes authored Jul 3, 2019
1 parent d8e69bc commit 3b822e4
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Notas das versões

## [1.8.2 - 02/07/2019](https://github.com/vindi/vindi-magento/releases/tag/1.8.2)

### Ajustado
- Corrige validação de quantidade de parcelas no checkout


## [1.8.1 - 10/06/2019](https://github.com/vindi/vindi-magento/releases/tag/1.8.1)

### Ajustado
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ Obs.: Gostamos muito do [MEQP1](https://github.com/magento/marketplace-eqp):smil


# Qualidade do código
Para garantir a qualidade do código, a gente disponibiliza alguns testes funcionais e code style MEQP1 do magento em Vindi/Subscription/tests.
Para garantir o controle da qualidade do código, disponibilizamos alguns testes via [Codecept](https://codecept.io/) em [Vindi/Subscription/tests](https://github.com/vindi/vindi-magento/tree/master/tests).

#### Se você nunca utilizou o composer, seja bem vindo :tada: :smile: [Aqui está o link do composer](https://getcomposer.org/download/), depois instale as dependências do composer.json.

#### Se você nunca rodou testes funcionais com Codeception, seja bem vindo :tada: :smile: [Aqui está o link da documentação oficial](https://codeception.com/docs/02-GettingStarted).
#### Se você nunca rodou testes funcionais com Codeception, seja bem vindo :tada: :smile: [Aqui está o link da documentação oficial](https://codeception.com/docs/01-Introduction).

## Rodando os Testes

Expand Down
31 changes: 16 additions & 15 deletions app/code/community/Vindi/Subscription/Block/Form/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,27 @@ public function isInstallmentsAllowedInStore()
*/
public function getInstallments()
{
$allowInstallments = $this->isInstallmentsAllowedInStore();
if (! $this->isInstallmentsAllowedInStore())
return false;

$maxInstallmentsNumber = $this->getMaxInstallmentsNumber();
$minInstallmentsValue = Mage::getStoreConfig('payment/vindi_creditcard/min_installment_value');
$quote = $this->getQuote();
$installments = false;

if ($maxInstallmentsNumber > 1 && $allowInstallments == true) {
$total = $quote->getGrandTotal();
$installmentsTimes = floor($total / $minInstallmentsValue);
$installments = '<option value="">' . Mage::helper('catalog')->__('-- Please Select --') . '</option>';

for ($i = 1; $i <= $maxInstallmentsNumber; $i++) {
$value = ceil($total / $i * 100) / 100;
$price = Mage::helper('core')->currency($value, true, false);
$installments .= '<option value="' . $i . '">' . sprintf('%dx de %s', $i, $price) . '</option>';
if(($i + 1) > $installmentsTimes)
break;
}
}

if ($maxInstallmentsNumber > 1) {
$total = $quote->getGrandTotal();
$installmentsTimes = floor($total / $minInstallmentsValue);
$installments = '<option value="">' . Mage::helper('catalog')->__('-- Please Select --') . '</option>';

for ($i = 1; $i <= $maxInstallmentsNumber; $i++) {
$value = ceil($total / $i * 100) / 100;
$price = Mage::helper('core')->currency($value, true, false);
$installments .= '<option value="' . $i . '">' . sprintf('%dx de %s', $i, $price) . '</option>';
if(($i + 1) > $installmentsTimes)
break;
}
}
return $installments;
}
/**
Expand Down
29 changes: 15 additions & 14 deletions app/code/community/Vindi/Subscription/Model/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,28 @@ public function validate()

public function validateInstallments($info)
{
$installments = $info->getAdditionalInformation('installments');
if (Mage::getStoreConfig('payment/vindi_creditcard/enable_installments')) {
$installments = $info->getAdditionalInformation('installments');

if (! $installments) {
return 'Você deve informar o número de parcelas.';
}
if (! $installments) {
return 'Você deve informar o número de parcelas.';
}

if ($installments != 1) {
$maxInstallmentNumber = Mage::getStoreConfig('payment/vindi_creditcard/max_installments_number');
if ($installments != 1) {
$maxInstallmentNumber = Mage::getStoreConfig('payment/vindi_creditcard/max_installments_number');

if ($installments > $maxInstallmentNumber) {
return 'O número de parcelas selecionado é inválido.';
}
if ($installments > $maxInstallmentNumber) {
return 'O número de parcelas selecionado é inválido.';
}

$minInstallmentsValue = Mage::getStoreConfig('payment/vindi_creditcard/min_installment_value');
$installmentValue = ceil($info->getQuote()->getGrandTotal() / $installments * 100) / 100;
$minInstallmentsValue = Mage::getStoreConfig('payment/vindi_creditcard/min_installment_value');
$installmentValue = ceil($info->getQuote()->getGrandTotal() / $installments * 100) / 100;

if (($installmentValue < $minInstallmentsValue) && ($installments > 1)) {
return 'O número de parcelas selecionado é inválido.';
if (($installmentValue < $minInstallmentsValue) && ($installments > 1)) {
return 'O número de parcelas selecionado é inválido.';
}
}
}

return 'valid';
}
}
2 changes: 1 addition & 1 deletion app/code/community/Vindi/Subscription/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Vindi_Subscription>
<version>1.8.1</version>
<version>1.8.2</version>
</Vindi_Subscription>
</modules>
<global>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $class = 'required-entry';
</label>

<div class="input-box">
<select name="payment[cc_installments]" class="required-entry">
<select id="vindi_cc_installments" name="payment[cc_installments]" class="required-entry">
<?php echo $installments; ?>
</select>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</label>

<div class="input-box">
<select name="payment[cc_installments]" class="required-entry">
<select id="vindi_cc_installments" name="payment[cc_installments]" class="required-entry">
<?php echo $installments; ?>
</select>
</div>
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.3'
services:
magento1_db:
image: vindi/mysql_magento1
container_name: magento1_db
ports:
- "3306"
magento1_web:
image: vindi/apache_magento1
container_name: magento1_web
depends_on:
- magento1_db
ports:
- "80:80"
links:
- magento1_db:mysql
networks:
default:
external:
name: webproxy
90 changes: 87 additions & 3 deletions tests/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,91 @@ class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;

/**
* Define custom actions here
*/
public function isModuleConfigured()
{
return getenv('CONFIGURED') == true;
}

public function goToAdminPanel($I)
{
$I->amOnPage('/admin');

try {
$I->fillField('login[username]', 'admin');
$I->fillField('login[password]', 'password123');
$I->click('Login');
} catch (Exception $e) { }
}

public function goToVindiSettings($I)
{
$I->click('System');
$I->click('Configuration');

try {
$I->seeElement('#vindi_subscription_general_api_key');
} catch (Exception $e) {
$I->click('#vindi_subscription_general-head');
}
}

public function setConnectionConfig($I)
{
$I->goToAdminPanel($I);
$I->goToVindiSettings($I);
$I->fillField('#vindi_subscription_general_api_key', getenv('VINDI_API_KEY'));
$I->selectOption('#vindi_subscription_general_sandbox_mode', 'Sandbox');
$I->click('Save Config');
putenv("CONFIGURED=true");
}

public function goToCreditCardSettings($I)
{
$I->click('System');
$I->click('Configuration');
$I->click('Payment Methods');

try {
$I->seeElement('#payment_vindi_creditcard_active');
} catch (Exception $e) {
$I->click('#payment_vindi_creditcard-head');
}
}

public function setDefaultCreditCard($I, $withInstallments = true, $maxInstallment = 12)
{
$I->goToAdminPanel($I);
$I->goToCreditCardSettings($I);
$I->selectOption('#payment_vindi_creditcard_active', 'Yes');
$I->selectOption(
'#payment_vindi_creditcard_enable_installments', $withInstallments ? 'Yes' : 'No'
);
$I->selectOption('#payment_vindi_creditcard_max_installments_number', "{$maxInstallment}x");
$I->click('Save Config');
}

public function addProductToCart($I)
{
$I->amOnPage('/vindi-product.html');
$I->click('Add to Cart');
$I->click('Proceed to Checkout');
}

public function loginAsUser($I)
{
$I->wait(1);
$I->amOnPage('/customer/account/login');
$I->fillField('login[username]', '[email protected]');
$I->fillField('login[password]', 'password123');
$I->click('Login');
}

public function skipCheckoutForm($I)
{
$I->click('#billing:use_for_shipping_yes');
$I->click('Continue', '#billing-buttons-container');
$I->wait(1);
$I->click('Continue', '#shipping-method-buttons-container');
$I->wait(1);
}
}
6 changes: 4 additions & 2 deletions tests/acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://localhost/myapp
- WebDriver:
url: http://vindi.magento/
browser: chrome
port: 9515
- \Helper\Acceptance
step_decorators: ~
Empty file removed tests/acceptance/.gitkeep
Empty file.
68 changes: 68 additions & 0 deletions tests/acceptance/vindiCheckoutWithCreditCardCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

class VindiCheckoutWithCreditCardCest
{
public function _before(AcceptanceTester $I)
{
// Caso o módulo não tenha sido configurado
if (! $I->isModuleConfigured())
$I->setConnectionConfig($I);
}

public function buyAnProductInInstallment(AcceptanceTester $I)
{
$I->setDefaultCreditCard($I, true);
$I->loginAsUser($I);
$I->addProductToCart($I);
$I->skipCheckoutForm($I);
$I->waitForElement('#dt_method_vindi_creditcard', 30);
$I->selectOption('dl#checkout-payment-method-load', 'Cartão de Crédito');
$I->waitForElement('#vindi_cc_installments', 30);
$I->selectOption('#vindi_cc_installments', '2');

try
{
$I->fillField('#vindi_creditcard_cc_owner', 'Vindi Magento');
$I->selectOption('#vindi_creditcard_cc_type', 'mastercard');
$I->fillField('#vindi_creditcard_cc_number', '5555555555555557');
$I->selectOption('select#vindi_creditcard_expiration.month', '12');
$I->selectOption('select#vindi_creditcard_expiration_yr.year', strval(date('Y') + 5));
$I->fillField('#vindi_creditcard_cc_cid', '123');
} catch(Exception $e) { }

$I->click('Continue', '#payment-buttons-container');
$I->waitForElement('#review-buttons-container', 30);
$I->click('Place Order');
$I->waitForElement('.main-container.col1-layout', 30);
$I->seeInCurrentUrl('/checkout/onepage/success');
$I->see('Your order has been received.');
}

public function buyAnProductWithoutInstallment(AcceptanceTester $I)
{
$I->setDefaultCreditCard($I, false);
$I->loginAsUser($I);
$I->addProductToCart($I);
$I->skipCheckoutForm($I);
$I->waitForElement('#dt_method_vindi_creditcard', 30);
$I->selectOption('dl#checkout-payment-method-load', 'Cartão de Crédito');
$I->dontSeeElement('select.required-entry');

try
{
$I->fillField('#vindi_creditcard_cc_owner', 'Vindi Magento');
$I->selectOption('#vindi_creditcard_cc_type', 'mastercard');
$I->fillField('#vindi_creditcard_cc_number', '5555555555555557');
$I->selectOption('select#vindi_creditcard_expiration.month', '12');
$I->selectOption('select#vindi_creditcard_expiration_yr.year', strval(date('Y') + 5));
$I->fillField('#vindi_creditcard_cc_cid', '123');
} catch(Exception $e) { }

$I->click('Continue', '#payment-buttons-container');
$I->waitForElement('#review-buttons-container', 30);
$I->click('Place Order');
$I->waitForElement('.main-container.col1-layout', 30);
$I->seeInCurrentUrl('/checkout/onepage/success');
$I->see('Your order has been received.');
}
}
30 changes: 30 additions & 0 deletions tests/acceptance/vindiCreditCardSettingsCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

class VindiCreditCardSettingsCest
{
public function _before(AcceptanceTester $I)
{
// Caso o módulo não tenha sido configurado
if (! $I->isModuleConfigured())
$I->setConnectionConfig($I);
}

public function enableCreditCardWithoutInstallments(AcceptanceTester $I)
{
$I->goToAdminPanel($I);
$I->goToCreditCardSettings($I);
$I->selectOption('#payment_vindi_creditcard_active', 'Yes');
$I->selectOption('#payment_vindi_creditcard_enable_installments', 'No');
$I->click('Save Config');
}

public function enableCreditCardWithInstallments(AcceptanceTester $I)
{
$I->goToAdminPanel($I);
$I->goToCreditCardSettings($I);
$I->selectOption('#payment_vindi_creditcard_active', 'Yes');
$I->selectOption('#payment_vindi_creditcard_enable_installments', 'Yes');
$I->selectOption('#payment_vindi_creditcard_max_installments_number', '12x');
$I->click('Save Config');
}
}
Loading

0 comments on commit 3b822e4

Please sign in to comment.