@@ -99,7 +99,8 @@ public function buildShippingProfile(string $shippingProfileType): array
99
99
$ allowedCountries = "* " ;
100
100
}
101
101
if ($ shippingProfileType === ShippingProfileTypes::TABLE_RATE ) {
102
- $ shippingMethods = $ this ->getShippingMethodsInfoForTableRates ();
102
+ $ selectedCondition = $ this ->getFieldFromModel (ShippingProfileTypes::TABLE_RATE , 'condition_name ' );
103
+ $ shippingMethods = $ this ->getShippingMethodsInfoForTableRates ($ selectedCondition );
103
104
} else {
104
105
$ shippingMethods = $ this ->buildShippingMethodsInfo ($ allowedCountries , $ price );
105
106
}
@@ -180,30 +181,34 @@ private function buildShippingMethodsInfo(string $allowedCountries, float $price
180
181
*
181
182
* Link: https://experienceleague.adobe.com/docs/commerce-admin/stores-sales/delivery/basic-methods/shipping-table-rate.html
182
183
*
184
+ * @param string $selectedCondition
183
185
* @return array
184
186
*/
185
- protected function getShippingMethodsInfoForTableRates (): array
187
+ protected function getShippingMethodsInfoForTableRates (string $ selectedCondition ): array
186
188
{
187
189
$ shippingMethodsInfo = [];
188
190
$ collection = $ this ->tableRateCollection ->create ();
189
191
$ collection ->getSelect ()
190
192
->joinLeft (
191
193
['region ' => $ collection ->getTable ('directory_country_region ' )],
192
194
'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 ') ]
194
196
);
195
197
foreach ($ collection as $ rate ) {
198
+ $ conditionName = $ rate ->getConditionName ();
199
+ if ($ conditionName !== $ selectedCondition ) {
200
+ continue ;
201
+ }
196
202
$ rate ->getName ();
197
203
// Determine the condition type (weight, price, or number of items)
198
204
$ conditionType = null ;
199
205
$ conditionValue = $ rate ->getConditionValue ();
200
- $ conditionName = $ rate ->getConditionName ();
201
206
if ($ conditionName === 'package_weight ' ) {
202
207
$ conditionType = 'weight ' ;
203
208
} elseif ($ conditionName === 'package_value_with_discount ' ) {
204
209
$ conditionType = 'price ' ;
205
210
} elseif ($ conditionName === 'package_qty ' ) {
206
- $ conditionType = 'item_qty ' ;
211
+ $ conditionType = 'number_of_items ' ;
207
212
}
208
213
$ shippingMethodsInfo [] = [
209
214
'price ' => $ rate ->getPrice (),
0 commit comments