If you close your own register, it should clear out your current order if one exists. Having a partially done order load up on a fresh register open is confusing and could lead to mistakes.

Comments

smccabe created an issue. See original summary.

fergy’s picture

This could either clear out automatically or maybe a prompt could appear asking you to void that transaction before you are able to close register. Whichever way would work as long as it is gone by the next open.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new20.33 KB

Here's another idea. Let's completely remove the concept of current order. It's not necessary. Without a current order this behaviour goes away.

alexpott’s picture

12 files changed, 62 insertions, 195 deletions. is the kind of diff stat I like.

Status: Needs review » Needs work

The last submitted patch, 3: 2941510-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new23.04 KB
new3.41 KB

Fixing the tests.

For me this change makes the parked order concept make sense since now we don't save an order unless you park it or complete it.

alexpott’s picture

  1. +++ b/commerce_pos.routing.yml
    @@ -32,10 +32,15 @@ commerce_pos.base:
     commerce_pos.main:
    -  path: '/admin/commerce/pos/main'
    +  path: '/admin/commerce/pos/main/{commerce_order}'
       defaults:
         _controller: '\Drupal\commerce_pos\POS::content'
         _title: 'Point of Sale Interface'
    +    commerce_order: null
    +  options:
    +    parameters:
    +      commerce_order:
    +        type: 'entity:commerce_order'
    
    @@ -89,15 +94,3 @@ commerce_pos.close_register:
    -commerce_pos.edit:
    -  path: '/admin/commerce/pos/order/{commerce_order}/edit'
    -  defaults:
    -    _controller: '\Drupal\commerce_pos\POS::content'
    -    _title: 'Point of Sale Edit Order'
    -  options:
    -    parameters:
    -      commerce_order:
    -        type: 'entity:commerce_order'
    -  requirements:
    -    _permission: 'access commerce pos pages'
    

    Another advantage of this change is that now editing an order has the same UI as creating - ie with the park buttons etc...

  2. +++ b/tests/src/FunctionalJavascript/ParkOrderTest.php
    @@ -100,9 +101,21 @@ class ParkOrderTest extends JavascriptTestBase {
    +    // Assert that the product is listed as expected.
    +    $web_assert->pageTextContains('Jumper');
    +    $web_assert->fieldValueEquals('order_items[target_id][order_items][0][quantity]', '1.00');
    +    $web_assert->fieldValueEquals('order_items[target_id][order_items][0][unit_price][number]', '50.00');
    +    $web_assert->pageTextContains('Total $50.00');
    +    $web_assert->pageTextContains('To Pay $50.00');
    

    This is a big improvement to this test. We weren't testing that the parked order that was retrieved correctly populated the form.

alexpott’s picture

Re-ordering the files.

alexpott’s picture

StatusFileSize
new1.04 KB
new23.73 KB

This will fail now I've committed #2944411: Add test for commerge_log integration. Here's a fix.

  • smccabe committed 3d6d957 on 8.x-2.x authored by alexpott
    Issue #2941510 by alexpott: Clear current order when closing your...
smccabe’s picture

Status: Needs review » Fixed

  • smccabe committed ccf9a0f on 8.x-2.x
    Revert of Issue #2941510 due to breaking bug causing the order to clean...
smccabe’s picture

Status: Fixed » Needs work

On further usage, this patch has a fairly significant side effect, due to the fact that we don't save the order anymore, if you move to any other page your POS form is wiped and you have to start from scratch, if you're just trying to check a customers old order or something this would be very very annoying.

I'm reverting this patch and putting it back to "needs work"

alexpott’s picture

So it behaves like a normal entity. Which is good because we were only saving an order on certain actions but not all. What we need is a piece of JS saying don't leave the page without parking.

smccabe’s picture

Disagree with that, it shouldn't behave like a regular entity form, it should behave like a cart like commerce proper does.

Parking an order is if you wish to stop that order, run a new order, then later continue your parked order. Needing to use it anytime you want to do anything else is a bad and unnecessary user experience, say if I am part way through an order a customer asks me to update their profile.

  • Park
  • Find Customer
  • Update
  • Find Parked Order
  • Unpark

It also means we couldn't do stuff like have a button to take you to that customer directly, if you'd loaded them up, it would make you park, but then you'd lose that order, or we'd have to build some sort of auto-park.

With a saved order the flow is much simpler

  • Find Customer
  • Update
  • Return to POS
alexpott’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new24.39 KB

But the problem is, for example, at the moment if you change the customer or add an adjustment the order is not saved. We only save the order if you add an order item or add a note.

Anyhow we can still remove the current order service and encapsulate it more to the POS class which should prevent it's usage everywhere - and also just store the ID so we're not providing something so convenient you wouldn't use the form state entity. And the patch adds back all the points where we saved the order before.

No interdiff cause rebase. Also we need to add tests around how current order works so we have the expectations tested. And we need to add tests about what happens if the register is closed.

smccabe’s picture

Status: Needs review » Needs work

Code looks good and works as expected, setting to Needs Work for the outstanding tests, everything else is good to go though.

smccabe’s picture

StatusFileSize
new24.4 KB

Rerolled patch to fix some minor conflicts

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new6.07 KB
new29.91 KB

Here's a test that ensures the expected current order logic works. One difference to the issue title summary is that if the current order matches the newly re-opened register it is not removed. I think that that makes sense. If you open a different register it is cleared.

Status: Needs review » Needs work

The last submitted patch, 19: 2941510-19.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review

There was a bot wobble seemingly.

joshmiller’s picture

Per Alex's point, we are postponing #2938694: Allow a Register to be changed until this patch lands.

smccabe’s picture

StatusFileSize
new30.07 KB
new1.14 KB

Everything about the patch is good except for the not clearing on the same register part. 99% of the time it will be the same register and the idea is that you don't start a new day with anything set, since it gives the possibility to add something extra to the first order of the day by mistake, where as the idea you'd want to resume a partially done order form the day before that you haven't parked is pretty unlikely.

Conversely, this code also prevents you from ever loading up an order on a different register, which you may want to do if you are resuming a parked order from a different till.

I changed the patch slightly by clearing the current order any time a new till is opened and removing the register doesn't match check.

Status: Needs review » Needs work

The last submitted patch, 23: 2941510-23.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

alexpott’s picture

Conversely, this code also prevents you from ever loading up an order on a different register, which you may want to do if you are resuming a parked order from a different till.

This makes sense but then what should the order's register be set to? The register that initiated or the register that finally took payment? My guess is that it should be updated on unparking.

smccabe’s picture

Status: Needs work » Needs review
StatusFileSize
new30.24 KB
new2.13 KB

@alexpott Agreed, added a line to set the register each time we load up an order.

I think one test is still failing, but it's not a test we changed, so I'm posting to see if it is just my local.

Status: Needs review » Needs work

The last submitted patch, 26: 2941510-26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

smccabe’s picture

Status: Needs work » Needs review
StatusFileSize
new30.21 KB

Fixed bug with saving order causing an out of sync issue.

joshmiller’s picture

A couple of nits. Leaving open for someone to review for functionality.

  1. +++ b/src/Form/POSForm.php
    @@ -761,8 +777,11 @@ class POSForm extends ContentEntityForm {
       /**
        * Clear the existing order, so a new one can be created.
        */
    -  protected function clearOrder() {
    -    \Drupal::service('commerce_pos.current_order')->clear();
    +  protected function clearOrder(FormStateInterface $form_state) {
    

    Missing @param

  2. +++ b/src/POS.php
    @@ -76,38 +70,43 @@ class POS extends ControllerBase {
    +      // If we're opening a new register, clear our current order if it exists
    +      // we don't want to pick up some older order at this point.
    +      $this->tempStore->set('current_order_id', FALSE);
    

    run-on sentence. Better:

    // If we're opening a new register, clear our current order. If it exists
    // we don't want to pick up some older order at this point.
    
  3. +++ b/src/Plugin/Field/FieldWidget/PosOrderItemWidget.php
    @@ -422,7 +424,7 @@ class PosOrderItemWidget extends WidgetBase implements WidgetInterface, Containe
    +    $order = $form_state->getFormObject()->getEntity();
    
    @@ -454,11 +454,9 @@ class PosOrderItemWidget extends WidgetBase implements WidgetInterface, Containe
    +    $order = $form_state->getFormObject()->getEntity();
    
    @@ -583,11 +572,11 @@ class PosOrderItemWidget extends WidgetBase implements WidgetInterface, Containe
    +    $order = $form_state->getFormObject()->getEntity();
    

    Is this better than getting it from the tempStore current_order_id variable?

  4. +++ b/src/Plugin/Field/FieldWidget/PosOrderItemWidget.php
    @@ -499,20 +497,15 @@ class PosOrderItemWidget extends WidgetBase implements WidgetInterface, Containe
    +    $order->addItem($new_order_item);
    

    Naming convention: We changed "$order" to "$commerce_order" above. Perhaps we should settle on one and change it all over?

  5. +++ b/tests/src/FunctionalJavascript/PosFormTest.php
    @@ -381,6 +383,93 @@ class PosFormTest extends JavascriptTestBase {
    +    $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/screen.jpg');
    ...
    +    $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/screen2.jpg');
    

    Are we just creating screenshots here or do we test for "expected screenshot similarity"?

smccabe’s picture

StatusFileSize
new40.37 KB

1. Fixed
2. Fixed
3. the entity is already loaded and also the most up to date, loading via ID would load the one from the db.
4. Checkin in commerce core, it does use both but mostly uses $order so changed everything to be $order
5. For debugging, removed

Status: Needs review » Needs work

The last submitted patch, 30: 2941510-30.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new11.91 KB
new33.06 KB

Let's file a follow-up for the $order standardisation. We'll need to change route parameters and go through the code with a fine tooth comb. It's just creating a lot of noise on this issue. Reverting this from #30 and fixing the PosForm too.

alexpott’s picture

Status: Needs review » Needs work
+++ b/src/Controller/POS.php
@@ -76,38 +70,43 @@ class POS extends ControllerBase {
+      $commerce_order = Order::load($current_order_id);
+      // Order may not have started on this register, so always set the register.
+      $commerce_order->set('field_register', $register->id());

Need to add test coverage of this.

alexpott’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new5.44 KB
new35.53 KB

Here's a test which yet again proves the old adage

Untested code is broken code

.

alexpott’s picture

Category: Task » Bug report
Priority: Normal » Major

I think fixing the code so that the order on the register that completes it is a major bug fix.

alexpott’s picture

StatusFileSize
new857 bytes
new35.97 KB

Updating for changes to HEAD.

alexpott’s picture

StatusFileSize
new35.88 KB

Rerolled after some cleanup.

alexpott’s picture

sorabh.v6’s picture

Assigned: Unassigned » sorabh.v6
sorabh.v6’s picture

Assigned: sorabh.v6 » Unassigned
Status: Needs review » Reviewed & tested by the community

I tried to find some knit picks :D. The patch is from @alexpott and very hard to find any knit picks. I checked the functionality and its working fine. I close my register it takes me to end-of-day reports page when I close the register. Then I again opened the POS by selecting the same register and the draft order was already gone.

Setting it to RTBC.

  • smccabe committed 7b5f3a2 on 8.x-2.x authored by alexpott
    Issue #2941510 by alexpott, smccabe, joshmiller, sorabh.v6, fergy: Clear...
smccabe’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.