Right now the main POS page just uses the basic "order items" field. This isn't really very useful, as we don't want to pick from a list of order items, what we really want to do is pick from a list of products and turn them into order items.

We should be able to copy the layout and functionality of the d7 version and make a nice widget for the order_item type that does this. As a bonus, this is probably useful even outside of the POS context, as it could be useful for any admin. Lets build it for POS right now and we can always spin it out into its own module if that proves a good idea.

Comments

smccabe created an issue. See original summary.

rigids’s picture

Assigned: Unassigned » rigids
smccabe’s picture

I added some config to use the basic order options, but this still needs to be done properly to match 7.x functionality.

rakesh.gectcr’s picture

Assigned: rigids » rakesh.gectcr

Talked to Shawn on DrupalCon Vienna Gonna work on it.

rakesh.gectcr’s picture

@Shawn I am able to ge the auto complete Field widget with image (For the database search Alpha1 and Alpha2 will be search_api lik we discussed). for the entity_reference field type. Can you please direct me how to include this into the POSForm::
i will give the widget patch tomorrow. Was trying to figure out the POSForm:: Its getting little complicated. Kindly please direct me.

rakesh.gectcr’s picture

Looks like it is coming from

core.entity_form_display.commerce_order.pos.default.yml Still I am not clear.

rakesh.gectcr’s picture

StatusFileSize
new5.81 KB

Just Uploaded the very rough patch of the work. Will be working tomorrow as well,

TODO: lot of things

1) Correct template to show the searching data(Title, image, price)
2) Add to the current order link
3) Filter with the current store.
4) Search API will be a separate issue. First I will complete with the Database API then search API

rakesh.gectcr’s picture

Status: Active » Needs review

Just checking for the test

rakesh.gectcr’s picture

StatusFileSize
new10.6 KB
new7.21 KB

Things are Done.
1) Auto Complete Widget for field
2) On the Close of Autocomplete. product will be automatically get added to Order / Cart. Sot it will be easy while doing the scanning also

Pending,
1) Theming for the widget
2) Filtering the product from the store.

@shawn please take a look at the patch.

smccabe’s picture

Status: Needs review » Needs work

Overall the architecture seems good, a couple designs flaws though, noted below.

You're mixed up again with using the correct order. POS orders don't use "carts" you want to use the POS currentOrder service to get the active POS order, not the cart manager, which is for frontend orders that customers make themselves.

When displaying products, everything in the POS uses product variations directly, not the product unless needed for extra info like description or image. For example, if i look up "shirt" it is going to show me all the variations of the shirt, small, medium, large, blue, green, red, etc. I then can add the specific one, I don't just want the overall product and then have to pick a bunch of options, thats too slow. If you look closely at the 7.x version, you'll see it's going direct as well.

gauravjeet’s picture

StatusFileSize
new3.07 KB

Yup, agree with smccabe's comment above. interdiff attached - this will show up product variations instead of product bundle itself.
Existing error: The Order Item widget has some issues while saving.

Caution: This change may not show product title in the absence of product attributes! so, a repeat of product title for different variations do not seem to be a good idea. Have to think of something better here.

rakesh.gectcr’s picture

Status: Needs work » Needs review
StatusFileSize
new12.58 KB
new10.62 KB

Please review.

smccabe’s picture

StatusFileSize
new1.44 KB

#12 wouldn't load a register correctly if already set, updated patch fixes that and also adds type hint for variation.

I was still unable to actually add a product though, would just highlight red and error, not sure of cause yet.

Status: Needs review » Needs work

The last submitted patch, 13: 2906515-13.patch, failed testing. View results

smccabe’s picture

Status: Needs work » Needs review
StatusFileSize
new12.75 KB

last patch was wrong, was missing new files, correct patch added.

smccabe’s picture

Status: Needs review » Needs work
StatusFileSize
new18.3 KB

WIP Patch, removes a bunch of the default formatting so we can style it better in the future, will still need to add proper theme/twig hook eventually. Also I changed some of the logic from using a product, to product variation, as thats what it should be using.

The main problem I am currently struggling with is converting the product variation to an order item in the right place. I tried adding a process callback to the element, but it causes the autocomplete to no longer get called for some reason. Doing it in the autocomplete is too soon, as it involves saving a lot of order_items that may never get used. Adding it to the POSForm #submit seemed too hacky, as then the widget isn't usable anywhere else and there must be a better way.

Possible solutions:

  • Figure out why process isn't working
  • Use a different was to adjust value (massageValues? valueCallback?)

Note: I used Inline Entity Form and Entity Autocomplete (core) as references for this, which helped but I got hungup on the creating the order_item, as autocomplete is too simple and IEF too complex.

Outstanding

  • Get conversion to order_item working properly
  • Update display so already added order items show up as line items nicely, instead of just crappy text fields (see POS 7.x)
  • Add ability to change quantity, price and remove to order items mentioned above. (again, see POS 7.x)
  • Have the autocomplete field show up above the already added items instead of below
  • Add a #theme call and twig template to properly theme widget
  • Add twig template for autocomplete display, instead of just hardcoded (not urgent)
rakesh.gectcr’s picture

When I am trying to apply above patch, I am getting the following error,

git apply -v 2906515-16.patch
Checking patch commerce_pos.libraries.yml...
error: while searching for:
  version: VERSION
  css:
    layout:
      css/commerce_pos.module.css: {}
error: patch failed: commerce_pos.libraries.yml:2
error: commerce_pos.libraries.yml: patch does not apply
Checking patch commerce_pos.routing.yml...
Checking patch js/commerce_pos_widget.js...
Checking patch src/Controller/AutoCompleteAddOrder.php...
Checking patch src/Controller/PosOrderItemAutoComplete.php...
Checking patch src/Form/POSForm.php...
error: while searching for:
      $formatted_amount = $number_formatter->formatCurrency(0, $default_currency);
    }


    $totals[] = ['Subtotal', $formatted_amount];

    // Commerce appears to have a bug where if not adjustments exist, it will return a

error: patch failed: src/Form/POSForm.php:77
error: src/Form/POSForm.php: patch does not apply
Checking patch src/Plugin/Field/FieldWidget/PosOrderItemWidget.php...
rob c’s picture

StatusFileSize
new17.87 KB

patch command gives similar output:

patch -p1 --dry-run < 2906515-16.patch
checking file commerce_pos.libraries.yml
Hunk #1 FAILED at 2.
1 out of 1 hunk FAILED
checking file commerce_pos.routing.yml
checking file js/commerce_pos_widget.js
checking file src/Controller/AutoCompleteAddOrder.php
checking file src/Controller/PosOrderItemAutoComplete.php
checking file src/Form/POSForm.php
Reversed (or previously applied) patch detected! Assume -R? [n] n
Apply anyway? [n] y
Hunk #1 FAILED at 77.
1 out of 1 hunk FAILED
checking file src/Plugin/Field/FieldWidget/PosOrderItemWidget.php

Rerolled the patch to apply to HEAD again. No further changes.

alexpott’s picture

StatusFileSize
new30.74 KB

Here's some work-in-progress. The widget is working to add purchasable items as order items to the order. It is using auto-complete and the order form is automatically updating once the order item has been added. I've also added a script that can be run using drush scr that sets up a commerce site for testing this - ie. it creates a store, some products and variations.

Still need to work on:

  • Add ability to change quantity, price and remove to order items mentioned above. (again, see POS 7.x)

The theming is going to be using view modes. The current patch allows you to select a view mode for autocomplete product selection and also for how the order items are viewed.

alexpott’s picture

StatusFileSize
new30.11 KB

Moved over to just using #ajax for all the processing - so no custom js or routes to update the order form.

Added buttons to increase and decrease quantity but they're not working quite right when you have more than one order item.

smccabe’s picture

Assigned: rakesh.gectcr » Unassigned
alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new40.54 KB

Added a javascript test and moved some of the ajax processing around. This is definitely ready for reviews now.

alexpott’s picture

StatusFileSize
new40.9 KB

Some code clean up.

Going to investigate why no tests running.

alexpott’s picture

StatusFileSize
new38.61 KB

I see... I was adding a fixture to make it easy for people / myself to set up a site for commerce_pos testing. Unfortunately run-tests.sh was not able to work out it is not a test :( - removing the fixture for now.

smccabe’s picture

Status: Needs review » Needs work

Overall works great, just a few display improvements to make 7.x parity

Turn SKU into link, remove label
Show unit price and make editable
Show adjustment option (possibly split this out into separate issue if it isn't easy)

Also minor, but there are a number of code sniff violations on the patch.

Note: we should create a follow up styling issue for this widget once this patch gets merged in.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new11.74 KB
new38.89 KB

Here's some coding standards fixes.

  1. Re sku into a link - I think this should be a separate followup issue. We're using view modes to control how everything looks so we should add a field formatter for this.
  2. Re making the order item unit price editable. That's interesting. I think that that means we need to move the order item list to being a form mode instead of a view mode.
  3. I'm not sure I understand what you mean by "show adjustment option".

Going to work on "making the order item unit price editable".

alexpott’s picture

So making the unit price editable and work nicely has been held up by the discovery of #2923388: Add #ajax support to the commerce_price form element

alexpott’s picture

StatusFileSize
new20.03 KB
new45.25 KB

I've moved the order items into a table - this will make it way easier to theme and I've move the quantity into a field. The latter brings up the point that maybe we just want to rely on HTML5 number fields for the + and - buttons since modern browsers will just add them to the number field. Also patch disables the ability to change the unit price because we're waiting on #2923388: Add #ajax support to the commerce_price form element. Tasks to bring this up to the same level as the Drupal 7 version is to handle adjustments and to add the ability to remove an order item with a single click.

I've left all the plumbing in for unit price changing including the tests so some code is commented out in the test but I think that is simpler.

alexpott’s picture

StatusFileSize
new6.65 KB
new44.29 KB

I've added the remove button and the removing the + and - for quantity as I don't think there is any need to maintain this. I've opened #2924956: Handle adjustments on POS form for fixing and testing adjustments.

One question for usability - should we default the minimum quantity to 1 so the only way to remove an order item is to click on the remove button. I think that that might make for better usability. Amazon's order form in the UK works this way but we are dealing with a different level of access to the system here and sometimes for cashiers speed is everything.

smccabe’s picture

Agree on the usability of not letting you minus below 1 and handling that with a remove. I will split that into a separate issue though as we've already got quite a big patch here and follow ups are better.

  • smccabe committed a557408 on 8.x-2.x authored by alexpott
    Issue #2906515 by alexpott, rakesh.gectcr, smccabe, Rob C, gauravjeet:...
smccabe’s picture

Status: Needs review » Fixed

Tested and review, all seemed to work well. Commited!

Thanks to everyone who bashed there head against this, it took a bit to come to the right solution.

Status: Fixed » Closed (fixed)

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