Skip to content

Commit c18de12

Browse files
committed
Merge remote-tracking branch 'origin/BUG#AC-2621' into Hammer_Quality_Backlog_GraphQl_13042022
2 parents 2504ba3 + 371da06 commit c18de12

File tree

4 files changed

+194
-4
lines changed

4 files changed

+194
-4
lines changed

app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public function collectRates(RateRequest $request)
111111
}
112112
} elseif ($item->getProduct()->isVirtual()) {
113113
$request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal());
114+
$request->setPackageValueWithDiscount(
115+
$request->getPackageValueWithDiscount() - $item->getBaseRowTotal()
116+
);
114117
}
115118
}
116119
}
@@ -133,8 +136,7 @@ public function collectRates(RateRequest $request)
133136
$freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
134137
}
135138
}
136-
} elseif (
137-
($item->getFreeShipping() || $item->getAddress()->getFreeShipping()) &&
139+
} elseif (($item->getFreeShipping() || $item->getAddress()->getFreeShipping()) &&
138140
($item->getFreeShippingMethod() == null || $item->getFreeShippingMethod() &&
139141
$item->getFreeShippingMethod() == 'tablerate_bestway')
140142
) {

dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Customer\Api\Data\GroupInterface;
1212
use Magento\Customer\Api\GroupRepositoryInterface;
1313
use Magento\Customer\Model\Vat;
14-
use Magento\Customer\Observer\AfterAddressSaveObserver;
1514
use Magento\Framework\Api\SearchCriteriaBuilder;
1615
use Magento\Framework\App\Config\MutableScopeConfigInterface;
1716
use Magento\Framework\DataObject;
@@ -23,7 +22,6 @@
2322
use Magento\Quote\Api\GuestShippingMethodManagementInterface;
2423
use Magento\Quote\Api\ShippingMethodManagementInterface;
2524
use Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver;
26-
use Magento\Quote\Observer\Frontend\Quote\Address\VatValidator;
2725
use Magento\Store\Model\ScopeInterface;
2826
use Magento\Tax\Api\Data\TaxClassInterface;
2927
use Magento\Tax\Api\TaxClassRepositoryInterface;
@@ -127,6 +125,47 @@ public function testTableRateFreeShipping()
127125
}
128126
}
129127

128+
/**
129+
* @magentoConfigFixture default_store carriers/tablerate/active 1
130+
* @magentoConfigFixture default_store carriers/flatrate/active 0
131+
* @magentoConfigFixture current_store carriers/tablerate/condition_name package_value_with_discount
132+
* @magentoConfigFixture default_store carriers/tablerate/include_virtual_price 0
133+
* @magentoDataFixture Magento/Sales/_files/quote_with_simple_and_virtual_product.php
134+
* @magentoDataFixture Magento/OfflineShipping/_files/tablerates_price.php
135+
* @return void
136+
*/
137+
public function testTableRateWithoutIncludingVirtualProduct()
138+
{
139+
$quote = $this->getQuote('quoteWithVirtualProduct');
140+
$cartId = $quote->getId();
141+
142+
if (!$cartId) {
143+
$this->fail('quote fixture failed');
144+
}
145+
146+
/** @var QuoteIdMask $quoteIdMask */
147+
$quoteIdMask = $this->objectManager
148+
->create(QuoteIdMaskFactory::class)
149+
->create()
150+
->load($cartId, 'quote_id');
151+
152+
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
153+
$shippingEstimation = $this->objectManager->get(GuestShippingMethodManagementInterface::class);
154+
$result = $shippingEstimation->estimateByExtendedAddress(
155+
$quoteIdMask->getMaskedId(),
156+
$quote->getShippingAddress()
157+
);
158+
159+
$this->assertCount(1, $result);
160+
$rate = reset($result);
161+
$expectedResult = [
162+
'method_code' => 'bestway',
163+
'amount' => 15,
164+
];
165+
$this->assertEquals($expectedResult['method_code'], $rate->getMethodCode());
166+
$this->assertEquals($expectedResult['amount'], $rate->getAmount());
167+
}
168+
130169
/**
131170
* Test table rate amount for the cart that contains some items with free shipping applied.
132171
*
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
11+
use Magento\Catalog\Model\Product\Type;
12+
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\Quote\Api\CartRepositoryInterface;
14+
use Magento\Quote\Model\Quote;
15+
use Magento\Quote\Model\Quote\Address;
16+
use Magento\Quote\Model\QuoteIdMask;
17+
use Magento\Quote\Model\QuoteIdMaskFactory;
18+
use Magento\Store\Model\StoreManagerInterface;
19+
use Magento\TestFramework\Helper\Bootstrap;
20+
21+
Bootstrap::getInstance()->loadArea('frontend');
22+
$objectManager = Bootstrap::getObjectManager();
23+
24+
$simpleProduct = $objectManager->create(Product::class)
25+
->setTypeId(Type::TYPE_SIMPLE)
26+
->setAttributeSetId(4)
27+
->setWebsiteIds([1])
28+
->setName('Simple Product')
29+
->setSku('simple-1')
30+
->setPrice(10)
31+
->setVisibility(Visibility::VISIBILITY_BOTH)
32+
->setStatus(Status::STATUS_ENABLED)
33+
->setCategoryIds([2])
34+
->setStockData([
35+
'use_config_manage_stock' => 1,
36+
'qty' => 100,
37+
'is_qty_decimal' => 0,
38+
'is_in_stock' => 1,
39+
])
40+
->save();
41+
42+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
43+
$productRepository->save($simpleProduct);
44+
45+
$virtualProduct = $objectManager->create(Product::class)
46+
->setTypeId(Type::TYPE_VIRTUAL)
47+
->setAttributeSetId(4)
48+
->setWebsiteIds([1])
49+
->setName('Virtual Product')
50+
->setSku('virtual-1')
51+
->setPrice(10)
52+
->setVisibility(Visibility::VISIBILITY_BOTH)
53+
->setStatus(Status::STATUS_ENABLED)
54+
->setCategoryIds([2])
55+
->setStockData([
56+
'use_config_manage_stock' => 1,
57+
'qty' => 100,
58+
'is_qty_decimal' => 0,
59+
'is_in_stock' => 1,
60+
])
61+
->save();
62+
63+
$productRepository->save($virtualProduct);
64+
65+
$addressData = include __DIR__ . '/address_data.php';
66+
$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
67+
$billingAddress->setAddressType('billing');
68+
69+
/** @var Address $shippingAddress */
70+
$shippingAddress = clone $billingAddress;
71+
$shippingAddress->setId(null)->setAddressType('shipping');
72+
73+
/** @var Quote $quote */
74+
$quote = $objectManager->create(Quote::class);
75+
$quote
76+
->setCustomerIsGuest(true)
77+
->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId())
78+
->setReservedOrderId('quoteWithVirtualProduct')
79+
->setBillingAddress($billingAddress)
80+
->setShippingAddress($shippingAddress)
81+
->setCustomerEmail('test@test.magento.com');
82+
$quote->addProduct($simpleProduct);
83+
$quote->addProduct($virtualProduct);
84+
85+
$quote->getShippingAddress()->setShippingMethod('tablerate_bestway');
86+
$quote->getPayment()->setMethod('checkmo');
87+
$quote->collectTotals();
88+
89+
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
90+
$quoteRepository->save($quote);
91+
92+
/** @var QuoteIdMask $quoteIdMask */
93+
$quoteIdMask = $objectManager->create(QuoteIdMaskFactory::class)->create();
94+
$quoteIdMask
95+
->setQuoteId($quote->getId())
96+
->setDataChanges(true)
97+
->save();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\CatalogInventory\Model\StockRegistryStorage;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Framework\Registry;
12+
use Magento\Quote\Model\Quote;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\TestFramework\ObjectManager;
15+
16+
/** @var $objectManager ObjectManager */
17+
$objectManager = Bootstrap::getObjectManager();
18+
19+
/** @var Registry $registry */
20+
$registry = $objectManager->get(Registry::class);
21+
$registry->unregister('isSecureArea');
22+
$registry->register('isSecureArea', true);
23+
24+
$quote = $objectManager->create(Quote::class);
25+
$quote->load('quoteWithVirtualProduct', 'reserved_order_id')->delete();
26+
27+
/**
28+
* @var ProductRepositoryInterface $productRepository
29+
*/
30+
$productRepository = Bootstrap::getObjectManager()
31+
->get(ProductRepositoryInterface::class);
32+
try {
33+
$product = $productRepository->get('simple-1', false, null, true);
34+
$productRepository->delete($product);
35+
} catch (NoSuchEntityException $e) {
36+
//Product already removed
37+
}
38+
39+
try {
40+
$customDesignProduct = $productRepository->get('virtual-1', false, null, true);
41+
$productRepository->delete($customDesignProduct);
42+
} catch (NoSuchEntityException $e) {
43+
//Product already removed
44+
}
45+
46+
/** @var StockRegistryStorage $stockRegistryStorage */
47+
$stockRegistryStorage = Bootstrap::getObjectManager()
48+
->get(StockRegistryStorage::class);
49+
$stockRegistryStorage->clean();
50+
51+
$registry->unregister('isSecureArea');
52+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)