Automatically Generated Coupons do not correctly honor Uses per Coupon and Uses per Customer settings.
ISSUE 1. When Uses per Customer = 1: A "Logged in" user who has used the first coupon code generated cannot used any other subsequent coupon code generated. Breaks assumption two.
ISSUE 2. When Uses per Coupon = 1: If a "Logged in" user has already used the first coupon code generated, a "Not Logged in" and or a "Logged in" user can still reuse the first coupon code. Breaks assumption one.
3.
4.
5.
Uses per coupon = 1 - Limits all users. Each coupon code generated can only be used once, and if used either by a "logged in" or "Not logged in" user uses, then that coupon code can no longer be used. However if two or more coupon codes were generated, after the first one has been used, the next coupon code can be used, but only once.
Users per customer = 1 -  Only limits "logged in" users. Any "logged in user can use the same generated coupon code, but they can use that code only once. So for example if 5 codes are generated, then any "logged in" use can use each code one time.
root@skynet:~# cat /proc/version
Linux version 3.16.0-4-amd64 ([email protected]) (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.39-1 (2016-12-30)
3.
root@skynet:~# composer -V
Composer version 1.3.0 2016-12-24 00:47:03
root@skynet:~# dpkg -l | grep php7
rc  libapache2-mod-php7.0                7.0.14-1~dotdeb+8.1                  amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php7.0                               7.0.15-1~dotdeb+8.1                  all          server-side, HTML-embedded scripting language (metapackage)
ii  php7.0-bcmath                        7.0.15-1~dotdeb+8.1                  amd64        Bcmath module for PHP
ii  php7.0-cli                           7.0.15-1~dotdeb+8.1                  amd64        command-line interpreter for the PHP scripting language
ii  php7.0-common                        7.0.15-1~dotdeb+8.1                  amd64        documentation, examples and common module for PHP
ii  php7.0-curl                          7.0.15-1~dotdeb+8.1                  amd64        CURL module for PHP
ii  php7.0-dev                           7.0.15-1~dotdeb+8.1                  amd64        Files for PHP7.0 module development
ii  php7.0-fpm                           7.0.15-1~dotdeb+8.1                  amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php7.0-gd                            7.0.15-1~dotdeb+8.1                  amd64        GD module for PHP
ii  php7.0-igbinary                      2.0.1-1~dotdeb+8.1                   amd64        igbinary serializer for PHP
ii  php7.0-imagick                       3.4.2-1~dotdeb+8.2                   amd64        Provides a wrapper to the ImageMagick library
ii  php7.0-intl                          7.0.15-1~dotdeb+8.1                  amd64        Internationalisation module for PHP
ii  php7.0-json                          7.0.15-1~dotdeb+8.1                  amd64        JSON module for PHP
ii  php7.0-mbstring                      7.0.15-1~dotdeb+8.1                  amd64        MBSTRING module for PHP
ii  php7.0-mcrypt                        7.0.15-1~dotdeb+8.1                  amd64        libmcrypt module for PHP
ii  php7.0-mysql                         7.0.15-1~dotdeb+8.1                  amd64        MySQL module for PHP
ii  php7.0-opcache                       7.0.15-1~dotdeb+8.1                  amd64        Zend OpCache module for PHP
ii  php7.0-pspell                        7.0.15-1~dotdeb+8.1                  amd64        pspell module for PHP
ii  php7.0-readline                      7.0.15-1~dotdeb+8.1                  amd64        readline module for PHP
ii  php7.0-redis                         3.1.0-1~dotdeb+8.4                   amd64        PHP extension for interfacing with Redis
ii  php7.0-soap                          7.0.15-1~dotdeb+8.1                  amd64        SOAP module for PHP
ii  php7.0-xml                           7.0.15-1~dotdeb+8.1                  amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP
ii  php7.0-xmlrpc                        7.0.15-1~dotdeb+8.1                  amd64        XMLRPC-EPI module for PHP
ii  php7.0-xsl                           7.0.15-1~dotdeb+8.1                  all          XSL module for PHP (dummy)
ii  php7.0-zip                           7.0.15-1~dotdeb+8.1                  amd64        Zip module for PHP
5.
root@skynet:~# dpkg -l | grep mariadb
ii  libmariadbclient18                   10.1.20+maria-1~jessie               amd64        MariaDB database client library
ii  mariadb-client                       10.1.20+maria-1~jessie               all          MariaDB database client (metapackage depending on the latest version)
ii  mariadb-client-10.1                  10.1.20+maria-1~jessie               amd64        MariaDB database client binaries
ii  mariadb-client-core-10.1             10.1.20+maria-1~jessie               amd64        MariaDB database core client binaries
ii  mariadb-common                       10.1.20+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/conf.d/mariadb.cnf)
ii  mariadb-server                       10.1.20+maria-1~jessie               all          MariaDB database server (metapackage depending on the latest version)
ii  mariadb-server-10.1                  10.1.20+maria-1~jessie               amd64        MariaDB database server binaries
ii  mariadb-server-core-10.1             10.1.20+maria-1~jessie               amd64        MariaDB database core server files
6.
root@skynet:~# dpkg -l | grep nginx
ii  libnginx-mod-http-auth-pam           1.10.2-2~dotdeb+8.2                  amd64        PAM authentication module for Nginx
ii  libnginx-mod-http-geoip              1.10.2-2~dotdeb+8.2                  amd64        GeoIP HTTP module for Nginx
ii  libnginx-mod-http-image-filter       1.10.2-2~dotdeb+8.2                  amd64        HTTP image filter module for Nginx
ii  libnginx-mod-http-lua                1.10.2-2~dotdeb+8.2                  amd64        LUA module for Nginx
ii  libnginx-mod-http-ndk                1.10.2-2~dotdeb+8.2                  amd64        Nginx Development Kit module
ii  libnginx-mod-http-perl               1.10.2-2~dotdeb+8.2                  amd64        Perl module for Nginx
ii  libnginx-mod-http-xslt-filter        1.10.2-2~dotdeb+8.2                  amd64        XSLT Transformation module for Nginx
ii  libnginx-mod-mail                    1.10.2-2~dotdeb+8.2                  amd64        Mail module for Nginx
ii  libnginx-mod-stream                  1.10.2-2~dotdeb+8.2                  amd64        Stream module for Nginx
ii  nginx-common                         1.10.2-2~dotdeb+8.2                  all          small, powerful, scalable web/proxy server - common files
ii  nginx-extras                         1.10.2-2~dotdeb+8.2                  amd64        nginx web/proxy server (extended version)
7.
root@skynet:~# dpkg -l | grep redis
ii  php5-redis                           2.2.5-1                              amd64        PHP extension for interfacing with Redis
ii  php7.0-redis                         3.1.0-1~dotdeb+8.4                   amd64        PHP extension for interfacing with Redis
ii  redis-server                         2:3.2.6-1~dotdeb+8.1                 amd64        Persistent key-value database with network interface
ii  redis-tools                          2:3.2.6-1~dotdeb+8.1                 amd64        Persistent key-value database with network interface (client)
8.
9.
10.
I agree with @azeemism We meet the same issue with same environment. The only thing is that we use 2.1.2, so the problem is not only in 2.1.3
I'ld like to add additional information.
In our case, the catalog price rule has a usage limit of 1 and usage per customer of 1 but ALL generated coupon doesn't include this restriction into the database. The only workaround is to change directly into the table salesrule_coupon of the database, the usage_limit and usage_customer value for each coupon then it works as expected.
Concrete the coupons are not correctly generated from the sales rule


I found how to solve the problem without coding or changing manually the database. It's just a workaround for end users and help also to understand why it doesn't work.
1) If you create a sales rule, save uage limit, usage per customer and expiration with unwanted values. Mark the auto-generation coupon if you need them and also create the amount . Save the sales rule
2) Go back to the edited sales rule, change again the usage limit, usage per customer and expiration values and save all. All your generated coupons will receive the values for the sales rule.
It works only when there is a change of the settings when you save the save rule otherwise it has no effect.
If you generate again coupon after those steps, you must change and save the settings again twice to be sure that it is took in account.
There is definitely a bug related to how are saved the sales rule and generated coupons

@diglin appreciate you sharing.
@diglin I don't believe your work around solves all the issues here.
For example if your set Uses per Customer = 1 then automatically generate 5 coupons. You would expect that the same logged in customer to be able to use each one of the 5 coupons one time only. 
This does not happen. After a customer uses one of the 5 coupons, that same customer cannot use any of the other 4 coupons, even through they each have a unique coupon code.
Unless one of the assumptions I stated above is incorrect, this is still a part of the issue that will not be solved by your workaround.

Once again, in the illustration, I could not use more that one of the unique coupon codes shown per customer. Once a customer uses one of the unique coupon codes generated, they can no longer use any of the other coupon codes...and this also extends to further coupons generated under the same rule.
Further, I would expect that if only 1 coupon code is automatically generated under a rule with Uses per Customer = 1, then every customer can us that same coupon code once. And if further coupon codes are automatically generated under the same rule, then each one of those additional coupon codes can be used once by every customer. 
I would expect that if you want to generate coupon codes that can only be used once, so that two logged in customers cannot use the same coupon code then you would set both
Uses per Coupon = 1
Uses per Coupon = 1
md5-e2dc9a4649026d2fcb56b760bd2e2738
Uses per Coupon = 100
md5-ac16a955342cccc24ab6dea74e6d8447
Uses per Coupon = 1
etc. However none of these are working properly.
@azeemism as written in Magento backend, the use per customer works only for logged in customer, not for guest. Are you testing as guest ? On my side, uses per customer worked correctly for logged in customers. I see on your screenshot that usage_limit is NULL. I think it should not. Check my pull request the workaround is better than the one with the several saving steps.
If you expect that it works per guest / customer, Uses per coupon = 1, 'Uses per customer = 1' and you generate X coupons.
I'm disappointed that Uses per customerdoesn't work for guest based on IP or session ID or something similar
@azeemism thank you for your report.
Please create one GitHub ticker per issue, do not mess different issues in one ticket even if they seem to be similar to you.
Please also describe Expected result and Actual result in corresponding sections, not above the description, as it is harder for understanding when it's necessary to scroll page up and down.
@veloraven Thanks for your comment. I have moved the second issue to ticket #8553 and have reformatted issue 1 in this ticket per your guidelines. Thanks for your support.
Automatically Generated Coupons do not correctly honor Uses per Customer setting.
root@skynet:~# cat /proc/version
Linux version 3.16.0-4-amd64 ([email protected]) (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.39-1 (2016-12-30)
3.
root@skynet:~# composer -V
Composer version 1.3.0 2016-12-24 00:47:03
root@skynet:~# dpkg -l | grep php7
rc  libapache2-mod-php7.0                7.0.14-1~dotdeb+8.1                  amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php7.0                               7.0.15-1~dotdeb+8.1                  all          server-side, HTML-embedded scripting language (metapackage)
ii  php7.0-bcmath                        7.0.15-1~dotdeb+8.1                  amd64        Bcmath module for PHP
ii  php7.0-cli                           7.0.15-1~dotdeb+8.1                  amd64        command-line interpreter for the PHP scripting language
ii  php7.0-common                        7.0.15-1~dotdeb+8.1                  amd64        documentation, examples and common module for PHP
ii  php7.0-curl                          7.0.15-1~dotdeb+8.1                  amd64        CURL module for PHP
ii  php7.0-dev                           7.0.15-1~dotdeb+8.1                  amd64        Files for PHP7.0 module development
ii  php7.0-fpm                           7.0.15-1~dotdeb+8.1                  amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php7.0-gd                            7.0.15-1~dotdeb+8.1                  amd64        GD module for PHP
ii  php7.0-igbinary                      2.0.1-1~dotdeb+8.1                   amd64        igbinary serializer for PHP
ii  php7.0-imagick                       3.4.2-1~dotdeb+8.2                   amd64        Provides a wrapper to the ImageMagick library
ii  php7.0-intl                          7.0.15-1~dotdeb+8.1                  amd64        Internationalisation module for PHP
ii  php7.0-json                          7.0.15-1~dotdeb+8.1                  amd64        JSON module for PHP
ii  php7.0-mbstring                      7.0.15-1~dotdeb+8.1                  amd64        MBSTRING module for PHP
ii  php7.0-mcrypt                        7.0.15-1~dotdeb+8.1                  amd64        libmcrypt module for PHP
ii  php7.0-mysql                         7.0.15-1~dotdeb+8.1                  amd64        MySQL module for PHP
ii  php7.0-opcache                       7.0.15-1~dotdeb+8.1                  amd64        Zend OpCache module for PHP
ii  php7.0-pspell                        7.0.15-1~dotdeb+8.1                  amd64        pspell module for PHP
ii  php7.0-readline                      7.0.15-1~dotdeb+8.1                  amd64        readline module for PHP
ii  php7.0-redis                         3.1.0-1~dotdeb+8.4                   amd64        PHP extension for interfacing with Redis
ii  php7.0-soap                          7.0.15-1~dotdeb+8.1                  amd64        SOAP module for PHP
ii  php7.0-xml                           7.0.15-1~dotdeb+8.1                  amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP
ii  php7.0-xmlrpc                        7.0.15-1~dotdeb+8.1                  amd64        XMLRPC-EPI module for PHP
ii  php7.0-xsl                           7.0.15-1~dotdeb+8.1                  all          XSL module for PHP (dummy)
ii  php7.0-zip                           7.0.15-1~dotdeb+8.1                  amd64        Zip module for PHP
5.
root@skynet:~# dpkg -l | grep mariadb
ii  libmariadbclient18                   10.1.20+maria-1~jessie               amd64        MariaDB database client library
ii  mariadb-client                       10.1.20+maria-1~jessie               all          MariaDB database client (metapackage depending on the latest version)
ii  mariadb-client-10.1                  10.1.20+maria-1~jessie               amd64        MariaDB database client binaries
ii  mariadb-client-core-10.1             10.1.20+maria-1~jessie               amd64        MariaDB database core client binaries
ii  mariadb-common                       10.1.20+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/conf.d/mariadb.cnf)
ii  mariadb-server                       10.1.20+maria-1~jessie               all          MariaDB database server (metapackage depending on the latest version)
ii  mariadb-server-10.1                  10.1.20+maria-1~jessie               amd64        MariaDB database server binaries
ii  mariadb-server-core-10.1             10.1.20+maria-1~jessie               amd64        MariaDB database core server files
6.
root@skynet:~# dpkg -l | grep nginx
ii  libnginx-mod-http-auth-pam           1.10.2-2~dotdeb+8.2                  amd64        PAM authentication module for Nginx
ii  libnginx-mod-http-geoip              1.10.2-2~dotdeb+8.2                  amd64        GeoIP HTTP module for Nginx
ii  libnginx-mod-http-image-filter       1.10.2-2~dotdeb+8.2                  amd64        HTTP image filter module for Nginx
ii  libnginx-mod-http-lua                1.10.2-2~dotdeb+8.2                  amd64        LUA module for Nginx
ii  libnginx-mod-http-ndk                1.10.2-2~dotdeb+8.2                  amd64        Nginx Development Kit module
ii  libnginx-mod-http-perl               1.10.2-2~dotdeb+8.2                  amd64        Perl module for Nginx
ii  libnginx-mod-http-xslt-filter        1.10.2-2~dotdeb+8.2                  amd64        XSLT Transformation module for Nginx
ii  libnginx-mod-mail                    1.10.2-2~dotdeb+8.2                  amd64        Mail module for Nginx
ii  libnginx-mod-stream                  1.10.2-2~dotdeb+8.2                  amd64        Stream module for Nginx
ii  nginx-common                         1.10.2-2~dotdeb+8.2                  all          small, powerful, scalable web/proxy server - common files
ii  nginx-extras                         1.10.2-2~dotdeb+8.2                  amd64        nginx web/proxy server (extended version)
7.
root@skynet:~# dpkg -l | grep redis
ii  php5-redis                           2.2.5-1                              amd64        PHP extension for interfacing with Redis
ii  php7.0-redis                         3.1.0-1~dotdeb+8.4                   amd64        PHP extension for interfacing with Redis
ii  redis-server                         2:3.2.6-1~dotdeb+8.1                 amd64        Persistent key-value database with network interface
ii  redis-tools                          2:3.2.6-1~dotdeb+8.1                 amd64        Persistent key-value database with network interface (client)
Users per customer = 1 -  Only limits "logged in" users. Any "logged in user can use the same generated coupon code, but they can use that code only once. So for example if 5 codes are generated, then any "logged in" use can use each code one time.Uses per Customer = 1: A "Logged in" user who uses one of the coupon codes generated in a batch of say 5 codes, cannot used any of the other 4 coupon codes in the batch, or any other subsequent coupon codes generated.Magento 2.1.4 CE also has the same issue
@azeemism thank you for report. I'm verifying this issue in connection to the PR #8355
I suspect that both assumptions are wrong. Checking the documentation, it appears that uses per customer and uses per coupon limits apply to the whole cart rule, not just to individual coupons. So that uses per coupon = 1 means that the customer who applied any coupon from the cart rule can apply cart rule just once. He cannot apply cart rule using different coupons.
While the assumptions you listed leads to the conclusion that uses per coupon = 1 means that the user can apply individual coupon once but the cart rule can be applied multiple times if there are multiple coupons. Same for the uses per customer
In short, these fields are related to cart rule, not to coupon.
Here is the excerpt from the internal documentation. I also send this thread for confirmation to product owners responsible for the cart rules.
internal wiki for future references
internal wiki for future references
internal wiki for future references
@vrann I have the same point of view of the expected result as @azeemism and looks like it works the same on Magento 1. It is also how I interpret it in your own internal wiki documentation.
Coupon rule are tight closed with the cart rule. A coupon rule and cart rule are the same.
Uses per coupon = number of time a coupon can be used to apply a rule.
Uses per customer = number of time a logged in customer can apply a rule.
Each coupon generated for a sales rule must inherit from the parent.
@azeemism
Uses per customer concerns the entire promotion (not the specific coupon as you extracted)
@diglin you are right with the definition of number of usage restriction. The only "but" is that only logged in users are respected for it.
Hi. to confirm the same bahavior in all M1 1.5-1.923 versions. logic is wrong and usage is per rule not per coupon. but, probably Amasty Generate Import coupons extension solves the problem for M1. for me individual unique coupon used should not disallow other coupons usage by the same customer. this is essentail feature for affiliate sites...
@azeemism, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.3.0-dev, 2.1.10, 2.2.1
@vrann ,
uses per coupon = 1means that the customer who applied any coupon from the cart rule can apply cart rule just once. He cannot apply cart rule using different coupons.
If that's the case, the setting should not be labelled as "Uses per coupon", but "Max number of uses", "Max orders the rule may be applied to" or something like that. Because "uses PER coupon" means exactly what you're saying it doesn't mean. And the coupons don't really play any part in that restriction, so word "coupon" should be omitted to avoid confusion.
It's just that the restriction, for some reason, becomes available only when a coupon restriction is enabled ("Specific Coupon").
Secondly, you're including the customer restriction into the uses per coupon = 1 example. Is this correct? Because, from the documentation text (both the description and the test), it seems it's a global setting, not per customer/user.
If it is not correct, then a label (or a label hint) "Max number of orders the rule may be applied to" and maybe even add "(regardless the customers)", would really be necessary to understand what it does.
If it is correct, then what is the difference between "Uses per coupon" and "Uses for customer"? Because then they both are global regarding the coupons and both are customer-specific.
I installed Magento 2.2.1 from scratch and did some testing. It seems to me that now @azeemism 's assumption No. 1 is true (and issue No. 2 is resolved): "Uses per coupon" setting is a global limit, for all users. And it restricts each coupon independently, not the whole cart rule. (So, no need to change the name, it is appropriate.)
And assumption No. 2 is still false: the "Uses per customer" setting restricts the use of the cart rule as such, regardless of the coupons.
We just had this issue with a client: coupon was set to 1 / 1 and a client used 3 times.
To reproduce just create a rule with 1/1, generate the code and use it more than 1 time.


@magento-engcom-team see above
Most helpful comment
We just had this issue with a client: coupon was set to 1 / 1 and a client used 3 times.
To reproduce just create a rule with 1/1, generate the code and use it more than 1 time.