Skip to content

Commit 344e8ea

Browse files
Fixing bugs related to table rate shipping options (#455)
* changes * removing trailing comma * removing unused variable * changtes
1 parent 49a31af commit 344e8ea

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

app/code/Meta/Sales/Plugin/ShippingData.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public function buildShippingProfile(string $shippingProfileType): array
9999
$allowedCountries = "*";
100100
}
101101
if ($shippingProfileType === ShippingProfileTypes::TABLE_RATE) {
102-
$shippingMethods = $this->getShippingMethodsInfoForTableRates();
102+
$selectedCondition = $this->getFieldFromModel(ShippingProfileTypes::TABLE_RATE, 'condition_name');
103+
$shippingMethods = $this->getShippingMethodsInfoForTableRates($selectedCondition);
103104
} else {
104105
$shippingMethods = $this->buildShippingMethodsInfo($allowedCountries, $price);
105106
}
@@ -180,30 +181,34 @@ private function buildShippingMethodsInfo(string $allowedCountries, float $price
180181
*
181182
* Link: https://experienceleague.adobe.com/docs/commerce-admin/stores-sales/delivery/basic-methods/shipping-table-rate.html
182183
*
184+
* @param string $selectedCondition
183185
* @return array
184186
*/
185-
protected function getShippingMethodsInfoForTableRates(): array
187+
protected function getShippingMethodsInfoForTableRates(string $selectedCondition): array
186188
{
187189
$shippingMethodsInfo = [];
188190
$collection = $this->tableRateCollection->create();
189191
$collection->getSelect()
190192
->joinLeft(
191193
['region' => $collection->getTable('directory_country_region')],
192194
'main_table.dest_region_id = region.region_id',
193-
['region.code AS region_code']
195+
[new \Zend_Db_Expr('IFNULL(region.code, \'*\') AS region_code')]
194196
);
195197
foreach ($collection as $rate) {
198+
$conditionName = $rate->getConditionName();
199+
if ($conditionName !== $selectedCondition) {
200+
continue;
201+
}
196202
$rate->getName();
197203
// Determine the condition type (weight, price, or number of items)
198204
$conditionType = null;
199205
$conditionValue = $rate->getConditionValue();
200-
$conditionName = $rate->getConditionName();
201206
if ($conditionName === 'package_weight') {
202207
$conditionType = 'weight';
203208
} elseif ($conditionName === 'package_value_with_discount') {
204209
$conditionType = 'price';
205210
} elseif ($conditionName === 'package_qty') {
206-
$conditionType = 'item_qty';
211+
$conditionType = 'number_of_items';
207212
}
208213
$shippingMethodsInfo[] = [
209214
'price' => $rate->getPrice(),

0 commit comments

Comments
 (0)