Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #120 from gmatsuoka/master
Browse files Browse the repository at this point in the history
fixed decimal places in Chile and Colombia
  • Loading branch information
gmatsuoka authored Jan 30, 2019
2 parents d35a2ea + e4c6872 commit af1d905
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"type": "magento2-component",
"version": "2.2.2",
"version": "2.2.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
30 changes: 26 additions & 4 deletions src/MercadoPago/Core/Model/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,29 +389,44 @@ protected function getCustomerInfo($customer, $order)
protected function getItemsInfo($order)
{
$dataItems = [];
$siteId = strtoupper($this->_scopeConfig->getValue('payment/mercadopago/country', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));

foreach ($order->getAllVisibleItems() as $item) {
$product = $item->getProduct();
$image = $this->_helperImage->init($product, 'image');

$unitPrice = (float) number_format($item->getPrice(), 2, '.', '');
//without decimal places in specific countrys
if($siteId == 'MLC' || $siteId == 'MCO'){
$unitPrice = (int) $unitPrice;
}

$dataItems[] = [
"id" => $item->getSku(),
"title" => $product->getName(),
"description" => $product->getName(),
"picture_url" => $image->getUrl(),
"category_id" => $this->_scopeConfig->getValue('payment/mercadopago/category_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
"quantity" => (int)number_format($item->getQtyOrdered(), 0, '.', ''),
"unit_price" => (float)number_format($item->getPrice(), 2, '.', '')
"unit_price" => $unitPrice
];
}

/* verify discount and add it like an item */
$discount = $this->getDiscount();
if ($discount != 0) {

$discount = (float)number_format($discount, 2, '.', '');
//without decimal places in specific countrys
if($siteId == 'MLC' || $siteId == 'MCO'){
$discount = (int) $discount;
}

$dataItems[] = array(
"title" => "Discount by the Store",
"description" => "Discount by the Store",
"quantity" => 1,
"unit_price" => (float)number_format($discount, 2, '.', '')
"unit_price" => $discount
);
}

Expand Down Expand Up @@ -463,7 +478,8 @@ public function makeDefaultPreferencePaymentV1($paymentInfo = [], $quote = null,

$billing_address = $quote->getBillingAddress()->getData();
$customerInfo = $this->getCustomerInfo($customer, $order);

$siteId = strtoupper($this->_scopeConfig->getValue('payment/mercadopago/country', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));

/* INIT PREFERENCE */
$preference = array();

Expand All @@ -474,9 +490,15 @@ public function makeDefaultPreferencePaymentV1($paymentInfo = [], $quote = null,
$preference['notification_url'] = $notification_url;
}

$transactionAmount = (float) $this->getAmount();;
//without decimal places in specific countrys
if($siteId == 'MLC' || $siteId == 'MCO'){
$transactionAmount = (int) $transactionAmount;
}

$preference['description'] = __("Order # %1 in store %2", $order->getIncrementId(), $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK));

$preference['transaction_amount'] = (float) $this->getAmount();
$preference['transaction_amount'] = $transactionAmount;

$preference['external_reference'] = $order->getIncrementId();

Expand Down
8 changes: 8 additions & 0 deletions src/MercadoPago/Core/Model/Standard/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ public function makePreference()
$arr['sponsor_id'] = (int)$sponsor_id;
}

//without decimal places in specific countrys
$siteId = strtoupper($this->_scopeConfig->getValue('payment/mercadopago/country', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
if($siteId == 'MLC' || $siteId == 'MCO'){
foreach($arr['items'] as $key => $item){
$arr['items'][$key]['unit_price'] = (int) $item['unit_price'];
}
}

return $arr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mercadopago/module-core",
"description": "Mercado Pago payment method module",
"type": "magento2-module",
"version": "2.2.2",
"version": "2.2.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MercadoPago_Core" setup_version="2.2.2">
<module name="MercadoPago_Core" setup_version="2.2.3">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/MercadoEnvios/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"php": "~5.5.0|~5.6.0|~7.0.0"
},
"type": "magento2-module",
"version": "2.2.2",
"version": "2.2.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/MercadoEnvios/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MercadoPago_MercadoEnvios" setup_version="2.2.2">
<module name="MercadoPago_MercadoEnvios" setup_version="2.2.3">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down

0 comments on commit af1d905

Please sign in to comment.