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

Friendly order numbers #184

Closed
angrybrad opened this issue Mar 28, 2018 · 17 comments
Closed

Friendly order numbers #184

angrybrad opened this issue Mar 28, 2018 · 17 comments
Assignees
Labels
💡 enhancement Ideas and suggestions

Comments

@angrybrad
Copy link
Member

Created by: Anonymous (arnotenhagen@gmail.com) on 2017/02/07 18:50:45 +0000
Votes at time of UserVoice import: 11


Use an auto increased integer for order numbers, just like https://github.com/bossanova808/CommerceFriendlyOrderNumbers. It should be awesome to add a prefix like "WEB" to get an order number like "WEB00001".

@angrybrad
Copy link
Member Author

Created by: Pete Eveleigh (pete@moresoda.co.uk) on 2017/09/13 13:41:15 +0000


It would be nice to be able to set a custom order number format too that is not necessarily sequential.
For example, 'ABC' . date('Yh') . rand(100,999)

@angrybrad
Copy link
Member Author

Created by: Anna Brown (anna@mediagirl.com) on 2017/09/23 18:33:14 +0000


Sorry guys, but how is this not already done? The numbering is not what clients are used to and having to add a plugin to get this working in an way that client's will accept is not cool.

@angrybrad
Copy link
Member Author

Created by: Stephen McIver (spm999@gmail.com) on 2017/12/01 17:29:03 +0000


I completely agree with Anna about this - how is this not already done?

It feels a bit hacky having to use a plugin for this (grateful though I am to the plugin developer for releasing it), as we now have a Reference number (the hash), an ID (the element ID I assume), and now a sequential friendly order number. :-/

@lukeholder lukeholder added the 💡 enhancement Ideas and suggestions label Mar 28, 2018
@lukeholder
Copy link
Member

We are considering adding friendly order numbers to Commerce 2-beta

The question is to what extent.

Would an integer only solution be enough? Will businesses expect to:

  • control the order number prefix?
  • have full control of the order number with something like Twig (with the incremented number being available)?

Please share your expectations. @sjelfull @bossanova808 @fantasticmachine @sm9

@peteeveleigh
Copy link
Contributor

peteeveleigh commented Jul 12, 2018 via email

@bossanova808
Copy link
Contributor

My thoughts are that the key thing is a consecutive integer, with a controllable starting point (so e.g. when you move systems your invoice number can carry on from where it was, or you start a new year and you increment from say invoice 10814 to 20000 or whatever, so there's an easy reference from the number to a point in time - i.e. the starting point should be changeable ongoingly, although not to a value less than has been used).

In terms of prefix etc - I always imagined that would be done with a twig expression really? But I have not thought a lot about it as we just use integers ourselves.

I do think the current (or next to be used) invoice number should be available as a twig variable (for silly ecommerce things like '20353 orders to date from customers just like you!' or whatever... and/or for doing maths like XXX order this month etc.

I definitely think this is a basic, essential feature of any ecommerce system. UIDs are useless to day to day order processing people and customers - it's just not what they expect to use to find orders. And clearly element IDs in Craft itself won't work as they are non consecutive for orders (and thus should be mostly hidden as they just confuse things in the context).

@sjcallender
Copy link
Contributor

As we are getting more and more Commerce 2 sites in the works, this continues to be one of the most confusing elements for clients. As Jeremy (bossanova808) said, the UIDs are useless and confusing for serious businesses that rely on order numbers for daily customer service and internal workflow actions. Getting something basic here as an MVP would be a huge relief.

@lukeholder lukeholder self-assigned this Sep 14, 2018
@lukeholder lukeholder changed the title Friendly order numbers as default Friendly order numbers Nov 9, 2018
@lukeholder
Copy link
Member

lukeholder commented Nov 13, 2018

@sjcallender @bossanova808 🎉🎉🎉

This uses the new "sequence" feature coming in the next release of Craft 3: craftcms/cms@edd3572

https://github.com/craftcms/commerce/blob/fe5034be1cf5aea4a3c574bd8c66f968818eb6df/docs/orders.md

@bossanova808
Copy link
Contributor

Hey Luke

This is great to see!

A couple of minor finishing things - people will need to facility to set a starting point for the sequence number, as many will be moving from existing settings. Is there a facility for this? I guess one could just do twig maths using say a global variable or something, but that seems a little naff....or I suppose twig maths will work in the mini-template too? If that is the intended mechanism. maybe update the docs with an example as that is bound to be a very common need for store operators.

I also think that the back end order templates should be changed to show the reference number as the primary large number at top, like this:

image

...and of course it should really be in the orders element index, and most likely the default sorting mechanism for orders there-in, and ideally is even the thing you click on to go into the order:

image

I've also opened an issue on Craft itself requesting that one can read the latest sequence number without incrementing it (using maybe an optional default false parameter to seq) - as you may want to we.g. print XXXX other customers have ordered YYYYY this month or similar as part of your marketing messaging...

...and finally, I will have a chat to you on Slack maybe about the best way of migrating my old Friendly order numbers to the new reference number, although I guess just looping through each order and copying the field value is that basic approach...

@lukeholder
Copy link
Member

lukeholder commented Nov 14, 2018

@bossanova808 setting the new starting point for the sequence is done by updating the craft_sequence table row for the name/key you are using with your new starting number.

Not sure what you mean by XXXX other customers have ordered YYYYY this month by needing the next order number without increment it?

If you want the number it can be retrieved with:

$next = (new Query())
            ->select(['next'])
            ->from('{{%sequence}}')
            ->where(['name' => 'myKeyName'])
            ->scalar();

On migrating old friendly number, yeah, you would loop over order records in a batched manor and update the order reference column with the custom field value.

@lukeholder
Copy link
Member

BTW, unless it wasn't clear you could also make a manual entry into the sequence table with a new starting number.

@bossanova808
Copy link
Contributor

Ok - re non increment that query (if documented!) is probably enough but I'll let Brandon respond to the issue since he asked me to make one.

I'm ok with editing a DB table of course, but shop owners may well want a UI for setting the starting number I would think. As they may want to do this each year or whatever...but I guess that is something you can gauge demand for/add later if need be!

@lukeholder
Copy link
Member

@bossanova808 the way the sequence function works is that it will start a new sequence when a new name/key is passed in. Passing in the dynamic year from the date as the key for example would automatically reset the counter. If you wanted to manually reset the counter, just update the name/key in the order reference format.

@boboldehampsink
Copy link
Contributor

boboldehampsink commented Nov 14, 2018

@lukeholder the added migration fails for me with the following error:

Yii Migration Tool (based on Yii v2.0.15.1)
    > add column reference string to table {{%commerce_orders}} ... done (time: 0.010s)
    > create index commerce_orders_reference_idx on {{%commerce_orders}} (reference) ... done (time: 0.011s)
Exception: SQLSTATE[42703]: Undefined column: 7 ERROR:  column "iscompleted" does not exist
LINE 1: ...erence"=LEFT("number", 7), "dateUpdated"=$1 WHERE isComplete...
                                                             ^
HINT:  Perhaps you meant to reference the column "commerce_orders.isCompleted".
The SQL being executed was: UPDATE "commerce_orders" SET "reference"=LEFT("number", 7), "dateUpdated"='2018-11-14 08:55:27' WHERE isCompleted = 1 (/app/vendor/yiisoft/yii2/db/Schema.php:664)

Using PostgreSQL 10.5

@lukeholder
Copy link
Member

@boboldehampsink just pushed fixes to develop branch if you want to try again.

@boboldehampsink
Copy link
Contributor

@lukeholder seems to be fine now, thanks :-)

@lukeholder
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 enhancement Ideas and suggestions
Projects
None yet
Development

No branches or pull requests

6 participants