Skip to content

Commit

Permalink
Merge pull request #50 from mundipagg/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
michelpl authored Feb 6, 2019
2 parents 9c9ecb7 + febc54a commit 2c780be
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ protected function createNewRequest($requestDataProvider)

$model = $this->getCreateCardHelper();
$card = $model->getById($payment->getAdditionalInformation('cc_saved_card'));

$order->payments = [
[
'payment_method' => 'credit_card',
Expand Down Expand Up @@ -376,7 +375,6 @@ protected function createNewRequest($requestDataProvider)
];
}else{
$tokenCard = $requestDataProvider->getCcTokenCreditCard();

$order->payments = [
[
'payment_method' => 'credit_card',
Expand Down
39 changes: 35 additions & 4 deletions Model/MundiPaggConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ class MundiPaggConfigProvider
/**
* Contains if the module is active or not
*/
const XML_PATH_SOFTDESCRIPTION = 'payment/mundipagg_creditcard/soft_description';

const XML_PATH_ATIVE = 'mundipagg_mundipagg/global/ative';
const XML_PATH_SOFTDESCRIPTION = 'payment/mundipagg_creditcard/soft_description';
const XML_PATH_ATIVE = 'mundipagg_mundipagg/global/ative';
const PATH_CUSTOMER_STREET = 'payment/mundipagg_customer_address/street_attribute';
const PATH_CUSTOMER_NUMBER = 'payment/mundipagg_customer_address/number_attribute';
const PATH_CUSTOMER_COMPLEMENT = 'payment/mundipagg_customer_address/complement_attribute';
const PATH_CUSTOMER_DISTRICT = 'payment/mundipagg_customer_address/district_attribute';


/**
Expand Down Expand Up @@ -76,7 +79,35 @@ public function validateSoftDescription()
*/
public function getModuleStatus()
{
return $this->scopeConfig->getValue(self::XML_PATH_ATIVE, ScopeInterface::SCOPE_STORE);
return
$this->scopeConfig->getValue(
self::XML_PATH_ATIVE,
ScopeInterface::SCOPE_STORE
);
}

public function getCustomerAddressConfiguration()
{
$street = $this->scopeConfig->getValue(
self::PATH_CUSTOMER_STREET,
ScopeInterface::SCOPE_STORE
);

$number = $this->scopeConfig->getValue(
self::PATH_CUSTOMER_NUMBER,
ScopeInterface::SCOPE_STORE
);

$district = $this->scopeConfig->getValue(
self::PATH_CUSTOMER_DISTRICT,
ScopeInterface::SCOPE_STORE
);

return [
'street' => $street,
'number' => $number,
'district' => $district
];
}

}
43 changes: 35 additions & 8 deletions Observer/CustomerAddressSaveBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,49 @@ public function moduleIsEnable()
return $mundipaggProvider->getModuleStatus();
}

public function getModuleAddressConfig()
{
$objectManager = ObjectManager::getInstance();
$mundipaggProvider = $objectManager->get(MundiPaggConfigProvider::class);
return $mundipaggProvider->getCustomerAddressConfiguration();
}

private function filterAddressIndexes($addressConfig)
{
$addressIndexes = [];

foreach ($addressConfig as $key => $value) {
if (preg_match('/street_\w{1}$/', $value) > 0) {
$addressIndexes[$key] = explode('street_', $value)[1];
}
}

return $addressIndexes;
}

/**
* @param $customerAddress
* @throws InputException
*/
public function addressValidation($customerAddress)
{
if(empty($customerAddress->getStreetLine(1))){
throw new InputException(__("Please check your address. First field of Street Address (Street) is required."));
}
$addressIndexes =
$this->filterAddressIndexes(
$this->getModuleAddressConfig()
);

if(empty($customerAddress->getStreetLine(2))){
throw new InputException(__("Please check your address. Second field of Street Address (Number) is required."));
}
if($addressIndexes) {
if(empty($customerAddress->getStreetLine($addressIndexes['street']))){
throw new InputException(__("Please check your address. Street Address field (Street) is required."));
}

if(empty($customerAddress->getStreetLine($addressIndexes['number']))){
throw new InputException(__("Please check your address. Street Address field (Number) is required."));
}

if(empty($customerAddress->getStreetLine(3))){
throw new InputException(__("Please check your address. Fourth field of Street Address (Neighborhood) is required."));
if(empty($customerAddress->getStreetLine($addressIndexes['district']))){
throw new InputException(__("Please check your address. Street Address field (Neighborhood) is required."));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mundipagg/mundipagg-magento2-module",
"license": "MIT",
"version": "1.4.12",
"version": "1.4.13",
"type": "magento2-module",
"description": "Magento 2 Module Mundipagg",
"require": {
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MundiPagg_MundiPagg" setup_version="1.4.12">
<module name="MundiPagg_MundiPagg" setup_version="1.4.13">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down
6 changes: 3 additions & 3 deletions i18n/pt_BR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@
"Brand","Tipo"
"Error to save MundiPagg Soft Description Credit Card, size too big max 22 character.","Erro para salvar MundiPagg Soft Descrição Cartão de crédito, tamanho muito grande máximo 22 caracteres."
"Max size 22.","Tamanho máximo 22."
"Please check your address. First field of Street Address (Street) is required.","Por favor, verifique seu endereço. O campo (Endereço) é obrigatório."
"Please check your address. Second field of Street Address (Number) is required.","Por favor, verifique seu endereço. O campo (Número) é obrigatório."
"Please check your address. Fourth field of Street Address (Neighborhood) is required.","Por favor, verifique seu endereço. O campo (Bairro) é obrigatório."
"Please check your address. Street Address field (Street) is required.","Por favor, verifique seu endereço. O campo endereço é obrigatório."
"Please check your address. Street Address field (Number) is required.","Por favor, verifique seu endereço. O campo número é obrigatório."
"Please check your address. Street Address field (Neighborhood) is required.","Por favor, verifique seu endereço. O campo bairro é obrigatório."
"Brand not exists.","Bandeira não existe."
"Name not informed.","Nome não informado."
"Month not informed.","Mês não informado."
Expand Down

0 comments on commit 2c780be

Please sign in to comment.