Skip to content
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

Closed
wants to merge 25 commits into from

Conversation

vasike
Copy link
Contributor

@vasike vasike commented Feb 23, 2017

No description provided.

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'));
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed. i'll do

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time service

Copy link
Contributor Author

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 {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrderExceptionInterface?

Copy link
Contributor Author

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',
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@bojanz
Copy link
Contributor

bojanz commented Jan 19, 2019

An updated patch is being posted to the issue.

@bojanz bojanz closed this Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants