Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
commerce_shipping-3381493
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
commerce_shipping-3381493
Commits
9e499c5b
Commit
9e499c5b
authored
6 years ago
by
Michael Lutz
Committed by
Bojan Živanović
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2920242
by mikelutz, bojanz: Shipment always using last shipping method's package type
parent
de2efb98
No related branches found
Branches containing commit
Tags
8.x-1.0-beta5
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/Field/FieldWidget/ShippingRateWidget.php
+5
-5
5 additions, 5 deletions
src/Plugin/Field/FieldWidget/ShippingRateWidget.php
tests/src/FunctionalJavascript/CheckoutPaneTest.php
+19
-0
19 additions, 0 deletions
tests/src/FunctionalJavascript/CheckoutPaneTest.php
with
24 additions
and
5 deletions
src/Plugin/Field/FieldWidget/ShippingRateWidget.php
+
5
−
5
View file @
9e499c5b
...
...
@@ -85,16 +85,12 @@ class ShippingRateWidget extends WidgetBase implements ContainerFactoryPluginInt
public
function
formElement
(
FieldItemListInterface
$items
,
$delta
,
array
$element
,
array
&
$form
,
FormStateInterface
$form_state
)
{
/** @var \Drupal\commerce_shipping\Entity\ShipmentInterface $shipment */
$shipment
=
$items
[
$delta
]
->
getEntity
();
$use_default_package_type
=
empty
(
$shipment
->
getPackageType
());
/** @var \Drupal\commerce_shipping\ShippingMethodStorageInterface $shipping_method_storage */
$shipping_method_storage
=
$this
->
entityTypeManager
->
getStorage
(
'commerce_shipping_method'
);
$shipping_methods
=
$shipping_method_storage
->
loadMultipleForShipment
(
$shipment
);
$options
=
[];
foreach
(
$shipping_methods
as
$shipping_method
)
{
$shipping_method_plugin
=
$shipping_method
->
getPlugin
();
if
(
$use_default_package_type
)
{
$shipment
->
setPackageType
(
$shipping_method_plugin
->
getDefaultPackageType
());
}
$shipping_rates
=
$shipping_method_plugin
->
calculateRates
(
$shipment
);
foreach
(
$shipping_rates
as
$shipping_rate
)
{
$service
=
$shipping_rate
->
getService
();
...
...
@@ -154,7 +150,11 @@ class ShippingRateWidget extends WidgetBase implements ContainerFactoryPluginInt
$shipping_method_storage
=
$this
->
entityTypeManager
->
getStorage
(
'commerce_shipping_method'
);
/** @var \Drupal\commerce_shipping\Entity\ShippingMethodInterface $shipping_method */
$shipping_method
=
$shipping_method_storage
->
load
(
$shipping_method_id
);
$shipping_method
->
getPlugin
()
->
selectRate
(
$shipment
,
$shipping_rate
);
$shipping_method_plugin
=
$shipping_method
->
getPlugin
();
if
(
empty
(
$shipment
->
getPackageType
()))
{
$shipment
->
setPackageType
(
$shipping_method_plugin
->
getDefaultPackageType
());
}
$shipping_method_plugin
->
selectRate
(
$shipment
,
$shipping_rate
);
// Put delta mapping in $form_state, so that flagErrors() can use it.
$field_state
=
static
::
getWidgetState
(
$form
[
'#parents'
],
$field_name
,
$form_state
);
...
...
This diff is collapsed.
Click to expand it.
tests/src/FunctionalJavascript/CheckoutPaneTest.php
+
19
−
0
View file @
9e499c5b
...
...
@@ -125,6 +125,24 @@ class CheckoutPaneTest extends CommerceBrowserTestBase {
'stores'
=>
[
$this
->
store
],
]);
/** @var \Drupal\commerce_shipping\Entity\PackageType $package_type */
$package_type
=
$this
->
createEntity
(
'commerce_package_type'
,
[
'id'
=>
'package_type_a'
,
'label'
=>
'Package Type A'
,
'dimensions'
=>
[
'length'
=>
20
,
'width'
=>
20
,
'height'
=>
20
,
'unit'
=>
'mm'
,
],
'weight'
=>
[
'number'
=>
20
,
'unit'
=>
'g'
,
],
]);
\Drupal
::
service
(
'plugin.manager.commerce_package_type'
)
->
clearCachedDefinitions
();
// Create two flat rate shipping methods.
$first_shipping_method
=
$this
->
createEntity
(
'commerce_shipping_method'
,
[
'name'
=>
'Overnight shipping'
,
...
...
@@ -132,6 +150,7 @@ class CheckoutPaneTest extends CommerceBrowserTestBase {
'plugin'
=>
[
'target_plugin_id'
=>
'flat_rate'
,
'target_plugin_configuration'
=>
[
'default_package_type'
=>
'commerce_package_type:'
.
$package_type
->
get
(
'uuid'
),
'rate_label'
=>
'Overnight shipping'
,
'rate_amount'
=>
[
'number'
=>
'19.99'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment