New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #2656818 by vasike, smccabe, bojanz: Implement optimistic locking for orders #649
Conversation
modules/cart/commerce_cart.module
Outdated
function commerce_cart_commerce_cart_form_validate($form, FormStateInterface $form_state) { | ||
// Re-load the order. | ||
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */ | ||
$order = Order::load($form_state->get('order_id')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use loadUnchanged
from storage to ensure it's fresh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. i'll do
modules/cart/commerce_cart.module
Outdated
@@ -138,6 +188,10 @@ function commerce_cart_form_commerce_order_form_alter(array &$form, FormStateInt | |||
// Move the cart element to the bottom of the meta sidebar container. | |||
$form['cart']['#group'] = 'meta'; | |||
$form['cart']['#weight'] = 100; | |||
// Warning it the order is cart and it was modified in the last hour. | |||
if (!empty($order->get('cart')->value) && (REQUEST_TIME - $order->getChangedTime()) < 3600) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Time service
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i did intentionally as i think soon we'll switch to 8.3 and use core time.
however i'll switch to Commerce Time till then. thanks
/** | ||
* Exception interface for all exceptions thrown by the Order module. | ||
*/ | ||
interface ExceptionInterface {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OrderExceptionInterface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
@@ -61,6 +61,11 @@ public function form(array $form, FormStateInterface $form_state) { | |||
'#type' => 'hidden', | |||
'#default_value' => $order->getChangedTime(), | |||
]; | |||
// Version must be sent to the client, for later overwrite error checking. | |||
$form['version'] = [ | |||
'#type' => 'hidden', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use #value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems it won't work with value. we need to send it to client.
…o 2656818-order-locking
…o 2656818-order-locking
…o 2656818-order-locking
…o 2656818-order-locking
…o 2656818-order-locking
…o 2656818-order-locking
…view has the order id argument.
6be1d5c
to
b8a7444
Compare
…o 2656818-order-locking
…o 2656818-order-locking
An updated patch is being posted to the issue. |
No description provided.