Skip to content

Commit 1d6374b

Browse files
committed
MC-36521: SQLSTATE[42S02]: Base table or view not found while placing order
1 parent dc560c2 commit 1d6374b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

app/code/Magento/Sales/Model/Order.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
313313
*/
314314
private $regionFactory;
315315

316+
/**
317+
* @var array
318+
*/
319+
private $regionItems;
320+
316321
/**
317322
* @param \Magento\Framework\Model\Context $context
318323
* @param \Magento\Framework\Registry $registry
@@ -412,6 +417,7 @@ public function __construct(
412417
->get(SearchCriteriaBuilder::class);
413418
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
414419
$this->regionFactory = $regionFactory ?: ObjectManager::getInstance()->get(RegionFactory::class);
420+
$this->regionItems = [];
415421

416422
parent::__construct(
417423
$context,
@@ -1337,6 +1343,7 @@ public function getTrackingNumbers()
13371343
*/
13381344
public function getShippingMethod($asObject = false)
13391345
{
1346+
// phpstan:ignore "Call to an undefined static method"
13401347
$shippingMethod = parent::getShippingMethod();
13411348
if (!$asObject || !$shippingMethod) {
13421349
return $shippingMethod;
@@ -1359,9 +1366,16 @@ public function getAddressesCollection()
13591366
$collection = $this->_addressCollectionFactory->create()->setOrderFilter($this);
13601367
if ($this->getId()) {
13611368
foreach ($collection as $address) {
1362-
$region->loadByName($address->getRegion(), $address->getCountryId());
1363-
if ($region->getName()) {
1364-
$address->setRegion($region->getName());
1369+
if (isset($this->regionItems[$address->getCountryId()][$address->getRegion()])) {
1370+
if ($this->regionItems[$address->getCountryId()][$address->getRegion()]) {
1371+
$address->setRegion($this->regionItems[$address->getCountryId()][$address->getRegion()]);
1372+
}
1373+
} else {
1374+
$region->loadByName($address->getRegion(), $address->getCountryId());
1375+
$this->regionItems[$address->getCountryId()][$address->getRegion()] = $region->getName();
1376+
if ($region->getName()) {
1377+
$address->setRegion($region->getName());
1378+
}
13651379
}
13661380
$address->setOrder($this);
13671381
}

0 commit comments

Comments
 (0)