Skip to content

Commit

Permalink
merge magento/2.3-develop into magento-honey-badgers/MC-23091-2.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-mts-svc authored Dec 2, 2019
2 parents 0c93e0e + 54bd0d8 commit 59a60e5
Show file tree
Hide file tree
Showing 24 changed files with 1,370 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ public function execute($entity, $arguments = [])
$productId = (int)$entity->getData($identifierField);

// prepare original data to compare
$origPrices = [];
$originalId = $entity->getOrigData($identifierField);
if (empty($originalId) || $entity->getData($identifierField) == $originalId) {
$origPrices = $entity->getOrigData($attribute->getName());
}

$origPrices = $entity->getOrigData($attribute->getName());
$old = $this->prepareOldTierPriceToCompare($origPrices);
// prepare data for save
$new = $this->prepareNewDataForSave($priceRows, $isGlobal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function testExecute(): void
];
$linkField = 'entity_id';
$productId = 10;
$originalProductId = 11;

/** @var \PHPUnit_Framework_MockObject_MockObject $product */
$product = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
Expand All @@ -124,7 +125,7 @@ public function testExecute(): void
->willReturnMap(
[
['tier_price', $originalTierPrices],
['entity_id', $productId]
['entity_id', $originalProductId]
]
);
$product->expects($this->atLeastOnce())->method('getStoreId')->willReturn(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ public function setShippingMethods($methods)
$addressId = $address->getId();
if (isset($methods[$addressId])) {
$address->setShippingMethod($methods[$addressId]);
$address->setCollectShippingRates(true);
} elseif (!$address->getShippingMethod()) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Set shipping methods for all addresses. Verify the shipping methods and try again.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,16 @@ public function testSetShippingMethods()
$methodsArray = [1 => 'flatrate_flatrate', 2 => 'tablerate_bestway'];
$addressId = 1;
$addressMock = $this->getMockBuilder(QuoteAddress::class)
->setMethods(['getId', 'setShippingMethod'])
->setMethods(['getId', 'setShippingMethod', 'setCollectShippingRates'])
->disableOriginalConstructor()
->getMock();

$addressMock->expects($this->once())->method('getId')->willReturn($addressId);
$this->quoteMock->expects($this->once())->method('getAllShippingAddresses')->willReturn([$addressMock]);
$addressMock->expects($this->once())->method('setShippingMethod')->with($methodsArray[$addressId]);
$addressMock->expects($this->once())
->method('setCollectShippingRates')
->with(true);
$this->quoteMock->expects($this->once())
->method('__call')
->with('setTotalsCollectedFlag', [false])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
$baseOrderItemTax = (double)$orderItem->getBaseTaxInvoiced();
$orderItemQty = (double)$orderItem->getQtyInvoiced();

if ($orderItemTax && $orderItemQty) {
if ($orderItemQty) {
/**
* Check item tax amount
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,18 @@ public function testCollect($orderData, $creditmemoData, $expectedResults)
}
$this->creditmemo->expects($this->any())
->method('roundPrice')
->will($this->returnCallback(
function ($price, $type) use (&$roundingDelta) {
if (!isset($roundingDelta[$type])) {
$roundingDelta[$type] = 0;
->will(
$this->returnCallback(
function ($price, $type) use (&$roundingDelta) {
if (!isset($roundingDelta[$type])) {
$roundingDelta[$type] = 0;
}
$roundedPrice = round($price + $roundingDelta[$type], 2);
$roundingDelta[$type] = $price - $roundedPrice;
return $roundedPrice;
}
$roundedPrice = round($price + $roundingDelta[$type], 2);
$roundingDelta[$type] = $price - $roundedPrice;
return $roundedPrice;
}
));
)
);

$this->model->collect($this->creditmemo);

Expand Down Expand Up @@ -610,6 +612,143 @@ public function collectDataProvider()
],
];

// scenario 6: 2 items, 2 invoiced, price includes tax, full discount, free shipping
// partial credit memo, make sure that discount tax compensation (with 100 % discount) is calculated correctly
$result['collect_with_full_discount_product_price'] = [
'order_data' => [
'data_fields' => [
'discount_amount' => -200.00,
'discount_invoiced' => -200.00,
'subtotal' => 181.82,
'subtotal_incl_tax' => 200,
'base_subtotal' => 181.82,
'base_subtotal_incl_tax' => 200,
'subtotal_invoiced' => 181.82,
'discount_tax_compensation_amount' => 18.18,
'discount_tax_compensation_invoiced' => 18.18,
'base_discount_tax_compensation_amount' => 18.18,
'base_discount_tax_compensation_invoiced' => 18.18,
'grand_total' => 0,
'base_grand_total' => 0,
'shipping_tax_amount' => 0,
'base_shipping_tax_amount' => 0,
'shipping_discount_tax_compensation_amount' => 0,
'base_shipping_discount_tax_compensation_amount' => 0,
'tax_amount' => 0,
'base_tax_amount' => 0,
'tax_invoiced' => 0,
'base_tax_invoiced' => 0,
'tax_refunded' => 0,
'base_tax_refunded' => 0,
'base_shipping_amount' => 0,
],
],
'creditmemo_data' => [
'items' => [
'item_1' => [
'order_item' => [
'qty_invoiced' => 1,
'tax_amount' => 0,
'tax_invoiced' => 0,
'tax_refunded' => null,
'base_tax_amount' => 0,
'base_tax_invoiced' => 0,
'base_tax_refunded' => 0,
'tax_percent' => 10,
'qty_refunded' => 0,
'discount_percent' => 100,
'discount_amount' => 100,
'base_discount_amount' => 100,
'discount_invoiced' => 100,
'base_discount_invoiced' => 100,
'row_total' => 90.91,
'base_row_total' => 90.91,
'row_invoiced' => 90.91,
'base_row_invoiced' => 90.91,
'price_incl_tax' => 100,
'base_price_incl_tax' => 100,
'row_total_incl_tax' => 100,
'base_row_total_incl_tax' => 100,
'discount_tax_compensation_amount' => 9.09,
'base_discount_tax_compensation_amount' => 9.09,
'discount_tax_compensation_invoiced' => 9.09,
'base_discount_tax_compensation_invoiced' => 9.09,
],
'is_last' => true,
'qty' => 1,
],
'item_2' => [
'order_item' => [
'qty_invoiced' => 1,
'tax_amount' => 0,
'tax_invoiced' => 0,
'tax_refunded' => null,
'base_tax_amount' => 0,
'base_tax_invoiced' => 0,
'base_tax_refunded' => null,
'tax_percent' => 10,
'qty_refunded' => 0,
'discount_percent' => 100,
'discount_amount' => 100,
'base_discount_amount' => 100,
'discount_invoiced' => 100,
'base_discount_invoiced' => 100,
'row_total' => 90.91,
'base_row_total' => 90.91,
'row_invoiced' => 90.91,
'base_row_invoiced' => 90.91,
'price_incl_tax' => 100,
'base_price_incl_tax' => 100,
'row_total_incl_tax' => 100,
'base_row_total_incl_tax' => 100,
'discount_tax_compensation_amount' => 9.09,
'base_discount_tax_compensation_amount' => 9.09,
'discount_tax_compensation_invoiced' => 9.09,
'base_discount_tax_compensation_invoiced' => 9.09,
],
'is_last' => false,
'qty' => 0,
],
],
'is_last' => false,
'data_fields' => [
'grand_total' => -9.09,
'base_grand_total' => -9.09,
'base_shipping_amount' => 0,
'tax_amount' => 0,
'base_tax_amount' => 0,
'invoice' => new MagentoObject(
[
'shipping_tax_amount' => 0,
'base_shipping_tax_amount' => 0,
'shipping_discount_tax_compensation_amount' => 0,
'base_shipping_discount_tax_compensation_amount' => 0,
]
),
],
],
'expected_results' => [
'creditmemo_items' => [
'item_1' => [
'tax_amount' => 0,
'base_tax_amount' => 0,
],
'item_2' => [
'tax_amount' => 0,
'base_tax_amount' => 0,
],
],
'creditmemo_data' => [
'grand_total' => 0,
'base_grand_total' => 0,
'tax_amount' => 0,
'base_tax_amount' => 0,
'shipping_tax_amount' => 0,
'base_shipping_tax_amount' => 0,
],
],
];

return $result;
}

Expand Down
20 changes: 16 additions & 4 deletions app/code/Magento/Sitemap/Model/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem;
use Magento\Framework\UrlInterface;
use Magento\Robots\Model\Config\Value;
use Magento\Sitemap\Model\ItemProvider\ItemProviderInterface;
Expand Down Expand Up @@ -191,6 +192,16 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento
*/
private $lastModMinTsVal;

/**
* @var Filesystem
*/
private $filesystem;

/**
* @var DocumentRoot
*/
private $documentRoot;

/**
* Initialize dependencies.
*
Expand Down Expand Up @@ -238,8 +249,9 @@ public function __construct(
) {
$this->_escaper = $escaper;
$this->_sitemapData = $sitemapData;
$documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
$this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath());
$this->documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
$this->filesystem = $filesystem;
$this->_directory = $filesystem->getDirectoryWrite($this->documentRoot->getPath());
$this->_categoryFactory = $categoryFactory;
$this->_productFactory = $productFactory;
$this->_cmsFactory = $cmsFactory;
Expand Down Expand Up @@ -727,8 +739,8 @@ protected function _getFormattedLastmodDate($date)
*/
protected function _getDocumentRoot()
{
// phpcs:ignore Magento2.Functions.DiscouragedFunction
return realpath($this->_request->getServer('DOCUMENT_ROOT'));
return $this->filesystem->getDirectoryRead($this->documentRoot->getPath())
->getAbsolutePath();
}

/**
Expand Down
Loading

0 comments on commit 59a60e5

Please sign in to comment.