bugfix #14940 default shipping methods order by position (ehibes)

This PR was merged into the 1.12 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.12 or 1.13 <!-- see the comment below -->                  |
| Bug fix?        | yes                                                       |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | no |
| Related tickets |                       |
| License         | MIT                                                          |


I propose this modification, in order that the default shipping method is selected according to the position of the methods in the admin, even when the customer does not have an address yet.

<!--
 - Bug fixes must be submitted against the 1.12 branch
 - Features and deprecations must be submitted against the 1.13 branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------
  default shipping methods order by position
  Merge branch 'Sylius:1.12' into 1.12
  Merge branch 'Sylius:1.12' into 1.12
  Behat scenario
  Add @api tag
  Update features/cart/shopping_cart/resolving_default_shipping_method_in_cart_summary_based_on_method_position.feature
This commit is contained in:
Jacob Tobiasz 2023-05-12 11:21:04 +02:00 committed by GitHub
commit 9ab7a66f7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 1 deletions

View file

@ -0,0 +1,17 @@
@shopping_cart
Feature: Viewing a cart summary with the correct default shipping method
In order to see details about my order
As a Visitor
I want see my cart summary with the correct shipping method based on its position
Background:
Given the store operates on a single channel in "United States"
And the store allows shipping with "Method 1" at position 2 with "$5.00" fee
And the store also allows shipping with "Method 2" at position 0 with "$6.00" fee
And the store has a product "T-Shirt banana" priced at "$10"
@ui @api
Scenario:
Given I added product "T-Shirt banana" to the cart
When I see the summary of my cart
Then my cart shipping total should be "$6.00"

View file

@ -143,6 +143,30 @@ final class ShippingContext implements Context
$this->saveShippingMethod($shippingMethod);
}
/**
* @Given /^the store(?:| also) allows shipping with "([^"]+)" at position (\d+) with ("[^"]+") fee$/
*/
public function theStoreAllowsShippingMethodWithNameAndPositionAndFee($name, $position, $fee): void
{
$channel = $this->sharedStorage->get('channel');
$configuration = $this->getConfigurationByChannels([$channel], $fee);
$shippingMethod = $this->shippingMethodExampleFactory->create([
'name' => $name,
'enabled' => true,
'zone' => $this->getShippingZone(),
'calculator' => [
'type' => DefaultCalculators::FLAT_RATE,
'configuration' => $configuration,
],
'channels' => [$channel],
]);
$shippingMethod->setPosition((int) $position);
$this->saveShippingMethod($shippingMethod);
}
/**
* @Given /^(this shipping method) is named "([^"]+)" in the ("[^"]+" locale)$/
*/

View file

@ -41,7 +41,6 @@ class ShippingMethodRepository extends BaseShippingMethodRepository implements S
return $this->createEnabledForChannelQueryBuilder($channel)
->andWhere('o.zone IN (:zones)')
->setParameter('zones', $zones)
->addOrderBy('o.position', 'ASC')
->getQuery()
->getResult()
;
@ -55,6 +54,7 @@ class ShippingMethodRepository extends BaseShippingMethodRepository implements S
->andWhere(':channel MEMBER OF o.channels')
->setParameter('channel', $channel)
->setParameter('enabled', true)
->addOrderBy('o.position', 'ASC')
;
}
}