Jump to content

help limiting individual item qty per purchase


Recommended Posts

Like many in these Covid-19 days I am having a significant problem keeping items on my shelf so everyone can get some.  While I have resisted doing it, I am at a point where I simply have to start limiting how much of each item a customer can purchase so that I am able to make sure all my customers are able to get something.  I may only be able to get 15 of an item per month, but many of my customers typically buy 5-10 at a time as a normal purchase.  Meaning two customers clean my inventory for the month out and no other customers get any.  Sure everything is sold I made my $, but now I have a bunch of unhappy customers that go buy from someone else because they need it right now, instead of being able to buy a few items to get them thru until I get more.

Is there a way to limit how much of each individual product my customers can purchase? So I could limit a customer to only being able to purchase say 2 of each item at a time?

pelletpeddler.com

CubeCart Version
6.2.2
PHP Version (5.6 Recommended)
7.3.18
MySQL Version
5.7.23-23
Link to post
Share on other sites

On 6/17/2020 at 1:57 PM, bsmither said:

This module is the opposite:
https://www.cubecart.com/extensions/plugins/minimum-order-values-plugin

You can make a request to the publisher of this plugin to change (or add the functionality of) the limit to a max per.

I have reached out to them, seems that they are pretty overwhelmed like most of us with the turmoil from Covid and other World events.

I noticed in this thread it was mentioned another way to limit things, but it was not clear if this was just a coding tweak or part of an add-on module?  My high volume items are 21.4# each my other slow moving are 1#, I could easily set max order weight to 115# which leaves room for 5 primary items and lots of slower moving ones, but will not allow 6 primary items.

But I m not sure where/how to do that?

 

Link to post
Share on other sites
  • 2 weeks later...

this works for me.

I wrote a small code a few years ago, where a customer had to reach a minimum order value before he could progress to checkout.

To limit certain items, i recently modified this to work on weight, then allocated a set weight to products.

In my case, it's latex gloves. each box of gloves has a weight allocated as 1.00,

Any order eceeding this limit throws up an error.

 

Go to Manage hooks, code snippets and add a new code snippet.

 

Heres the code, based on a weight of 10 (10 boxes of gloves)

 

<?php
$upper_val=99999999.00;
$lower_val=10.00;
$value = number_format($upper_val, 2);
if($GLOBALS['cart']->basket['weight'] > $lower_val && $GLOBALS['cart']->basket['weight'] < $value) {
$GLOBALS['gui']->setError ('You Appear to have exceeded our gloves allowance - Sorry');
$GLOBALS['smarty']->assign('DISABLE_CHECKOUT_BUTTON', true);
}
?>

 

also see attached image.

 

 

snippet.jpg

Link to post
Share on other sites
4 hours ago, keat said:

this works for me.

I wrote a small code a few years ago, where a customer had to reach a minimum order value before he could progress to checkout.

To limit certain items, i recently modified this to work on weight, then allocated a set weight to products.

In my case, it's latex gloves. each box of gloves has a weight allocated as 1.00,

Any order exceeding this limit throws up an error.

 

Go to Manage hooks, code snippets and add a new code snippet.

 

Heres the code, based on a weight of 10 (10 boxes of gloves)

 

<?php
$upper_val=99999999.00;
$lower_val=10.00;
$value = number_format($upper_val, 2);
if($GLOBALS['cart']->basket['weight'] > $lower_val && $GLOBALS['cart']->basket['weight'] < $value) {
$GLOBALS['gui']->setError ('You Appear to have exceeded our gloves allowance - Sorry');
$GLOBALS['smarty']->assign('DISABLE_CHECKOUT_BUTTON', true);
}
?>

Thank you for that idea!  Did you do anything else in code anyplace or certain modules added to the site? 

I entered that snippet and it is not giving the message or disabling checkout.  I am seeing garbage text/code at the top of the basket page, so it seems like it is trying.  All my items have a weight assigned already.  I enabled weight display in cart so I know I am under/over the limit.  I set my limit to 110, as my items weigh 21# each, so they can buy 5 but not 6.  Any ideas?

code.thumb.png.1696e8a369a87fe08d2c158839ba962b.pngerror.thumb.png.b2d2cb4be8ea1c32f1b8c476f42ee0b2.png

Link to post
Share on other sites
Posted (edited)

Still not seeing it.

Ah! It's in View Basket.

So, something that has to do with calculating the Basket.

Edited by bsmither
Link to post
Share on other sites
Posted (edited)

Looking at your screen shot of the Snippet Editor, it suggests to me that, at least for this admin function, your site is not at CC622, but a version somewhat older.

A version that does not use the ACE programmer's editor. To verify, look at the admin skin template settings.hooks.php:

Near line 106:

         <fieldset>
         <legend>{$LANG.hooks.php_code}</legend>
         <div id="php_code"></div>
         <input type="hidden" name="snippet[php_code]" id="php_code_base64" class="textbox" value="{$SNIPPET.php_code_base64}">
         <script src="includes/ace/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
         <script>
            var editor = ace.edit("php_code");
            var input = document.getElementById('php_code_base64');
            editor.setOptions({
                useWrapMode: true,
                highlightActiveLine: true,
                showPrintMargin: false,
                theme: 'ace/theme/github',
                mode: 'ace/mode/php'
            });
            editor.setValue(window.atob("{$SNIPPET.php_code_base64}"), 1);
            editor.getSession().on("change", function () {
               input.value = window.btoa(editor.getSession().getValue());
            });
         </script>
         <input type="hidden" name="snippet[snippet_id]" id="snippet_id" class="textbox" value="{$SNIPPET.snippet_id}">
      </fieldset>

If the above is NOT what you see, then you may need to code your snippet as follows:

[PHP]
code...code....code
[/PHP]

There could be other reasons for the rogue text. The fact that it is not 100% human-readable suggests some admin code is believing this to be already a base64_encoded string, then decoding it into something unreadable. That would suggest the ACE editor is not starting. (On the other hand, the fact that the Version and Author text entry fields are below the PHP Code textarea box is another indication this admin function is an older version - perhaps in the CC6.1 family.)

 

Edited by bsmither
Link to post
Share on other sites
Posted (edited)

1st off thanks for looking into it, both of you! 
I will check that file when I get home tonight as I do not have ftp/file access where I am currently.

I went ahead and placed the original php commands to the [ ] enclosed ones.  No change in the gibberish and it still allows checkout.

Not sure why I would be on anything less than 622?  I upgraded quite a while ago and it says I am up to date.  What do you recommend for me to get it up to date?

image.thumb.png.7c3e49b7f5b6f304a7270df286e00d58.png

Edited by Lamrith
Link to post
Share on other sites
Posted (edited)

It appears you went from CC611 directly to CC622. The "Upgrade History" shows the progression (all on the same day) that the CC622 setup code took the database schema. (That is, this list is not to be interpreted as the progression of the actual CubeCart codebase.)

Do you recall ever having to deal with more than one admin PHP script file, and more than one admin folder, perhaps one of each file/folder name having different random characters as part of the name, after the upgrade?

CubeCart will read the value of the constant 'CC_VERSION' as set in the file ini.inc.php. CubeCart does NOT examine the actual codebase files for key indicators of a specific version (such as the comment block at the top of every file - not that there is any version indication there anyways). So, an installation could have the ini.inc.php file from CC622, but have a different version - inadvertently - of the entire, or parts of, the administration folder.

Edited by bsmither
Link to post
Share on other sites

I do not get into my file system at all unless something breaks.  I recall for a while i had to use "domain/admin_abc.php" then with one upgrade it forced me to change that to "domain/admin_xyz.php"

I can see that there is an "admin" folder and one "admin_xxxxxx" in the public html folder as well.

my ini.inc.php in root directory shows a last modified date of Aug/7/2018

 

Does any of that help?

Link to post
Share on other sites
5 hours ago, bsmither said:

Looking at your screen shot of the Snippet Editor, it suggests to me that, at least for this admin function, your site is not at CC622, but a version somewhat older.

A version that does not use the ACE programmer's editor. To verify, look at the admin skin template settings.hooks.php:

Near line 106:

         <fieldset>
         <legend>{$LANG.hooks.php_code}</legend>
         <div id="php_code"></div>
         <input type="hidden" name="snippet[php_code]" id="php_code_base64" class="textbox" value="{$SNIPPET.php_code_base64}">
         <script src="includes/ace/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
         <script>
            var editor = ace.edit("php_code");
            var input = document.getElementById('php_code_base64');
            editor.setOptions({
                useWrapMode: true,
                highlightActiveLine: true,
                showPrintMargin: false,
                theme: 'ace/theme/github',
                mode: 'ace/mode/php'
            });
            editor.setValue(window.atob("{$SNIPPET.php_code_base64}"), 1);
            editor.getSession().on("change", function () {
               input.value = window.btoa(editor.getSession().getValue());
            });
         </script>
         <input type="hidden" name="snippet[snippet_id]" id="snippet_id" class="textbox" value="{$SNIPPET.snippet_id}">
      </fieldset>

If the above is NOT what you see, then you may need to code your snippet as follows:

[PHP]
code...code....code
[/PHP]

There could be other reasons for the rogue text. The fact that it is not 100% human-readable suggests some admin code is believing this to be already a base64_encoded string, then decoding it into something unreadable. That would suggest the ACE editor is not starting. (On the other hand, the fact that the Version and Author text entry fields are below the PHP Code textarea box is another indication this admin function is an older version - perhaps in the CC6.1 family.)

 

Circling back to this one..

In public_html/admin/skins/default/templates/settings.hooks.php file I do have the code above.

In public_html/admin_xxxxx/skins/default/templates/settings.hooks.php I do not have that code. It has 

Quote

 <div id="snippets_import" class="tab_content">
      <h3>{$LANG.hooks.title_import_code_snippets}</h3>
      <p>{$LANG.hooks.example_code_snippet_xml}</p>
      <fieldset>
         <legend>{$LANG.hooks.browse_for_file}</legend>
         <input type="file" name="code_snippet_import" id="code_snippet_import">
      </fieldset>
   </div>
   {/if}
   {if $DISPLAY_HOOKS}
   <div id="hooks" class="tab_content">
      <h3>{$PLUGIN}</h3>
      <fieldset>
         <legend>{$LANG.hooks.title_hook_available}</legend>
         {foreach from=$HOOKS item=hook}
         <div>
            <span class="actions">
            <a href="{$hook.edit}"><i class="fa fa-pencil-square-o" title="{$LANG.common.edit}"></i></a>
            </span>
            <input type="hidden" name="status[{$hook.hook_id}]" value="{$hook.enabled}" id="status_{$hook.hook_id}" class="toggle">
            <a href="{$hook.edit}">{$hook.hook_name}</a>
         </div>
         {foreachelse}
         <div>{$LANG.hooks.error_hook_none}</div>
         {/foreach}
      </fieldset>
      <p>{$LANG.hooks.notify_hook_magic}</p>
   </div>
   {/if}

 

Link to post
Share on other sites

In public_html/admin_xxxxx/skins/default/templates/settings.hooks.php:

Near line 89:

         <div>
            <label for="php_code">{$LANG.hooks.php_code}</label>
            <span><textarea id="php_code" class="required" rows="12" cols="50">{$SNIPPET.php_code}</textarea></span>
         </div>
         <div>
            <label for="version">{$LANG.hooks.version}</label>
            <span>
            <input type="text" name="snippet[version]" id="version" class="textbox" value="{$SNIPPET.version}">
            </span>
         </div>
         <div>
            <label for="author">{$LANG.hooks.author}</label>
            <span>
            <input type="text" name="snippet[author]" id="author" class="textbox" value="{$SNIPPET.author}">
            </span>
         </div>
         <input type="hidden" name="snippet[snippet_id]" id="snippet_id" class="textbox" value="{$SNIPPET.snippet_id}">
         <input type="hidden" name="snippet[php_code]" id="php_code_base64" class="textbox" value="{$SNIPPET.php_code_base64}">

This is from CC611.

Look at the contents of ini.inc.php. Near line 54 is the version of the codebase that is being reported as installed.

Look at the contents of /includes/global.inc.php. There are two variables that will state the actual file/folder of the admin being used.

From what you have said, I will make these suggestions:

Rename the folder currently named admin_xxxxx to admin_xxxxx_611. Then, rename the folder currently named admin to admin_xxxxx. (Make sure that this new instance of admin_xxxxx matches exactly the value for the admin folder in global.inc.php.)

When you next ask for an administrative page, be sure to do so along with forcing your browser to fetch all new copies of page resources. This is typically done with CTRL-F5.

Link to post
Share on other sites

Well I tried renaming the Dir and the website stopped responding to anything I did in admin pages, even after ctrl-f5.  I changed names back and was able to control the site again.  I tried again to rename and now it is not even acting like I changed the version.  If I rename the Dir it simply will not let me do anything on admin level, nothing saves.

 

What do I do to re-install 6.2.2 or upgrade to 6.2.9?  When I tried the built in upgrade when it said I was behind a revision it told me I was up to date after trying to run.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...