The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.
 
 
Thread Tools Display Modes
  #11  
Old 02-18-2015, 11:32 AM
enot's Avatar
enot is offline
 
Join Date: Oct 2014
Posts: 499
Default


Quote:
Originally Posted by Th sp View Post
Hi Stephan,

Thank you very much!
I appreciate the help.

I did try your code. It does change the Qty to 5, but unfortunately it does so for ALL products.
Have not been able to fix it yet.

Any ideas?

Thanks!
Hi!

Sorry, I've indeed missed a couple of parts while editing, that's why the second condition was ignored, and the script changed quantity for all product pages.

To make this work, id's should be wrapped in brackets, and "productId" should be replaced with "page.productID".

Here's the code that should do the trick (This and my previous messages were edited, to prevent anyone else from getting the wrong script).

Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
if (typeof(Ecwid) == 'object') {
Ecwid.OnPageLoaded.add(function(page) {
var pids = [3432333, 3432332, 4543212];
if ('PRODUCT' == page.type)
for(var i=0; i<pids.length; i++) {
if (pids[i]==page.productId)
{
$('input.ecwid-productBrowser-details-qtyTextField').val('5');
}
}
});
}
</script>

Hope this helps.

Last edited by enot; 02-18-2015 at 07:31 PM. Reason: Corrected the code, left a note
  #12  
Old 02-18-2015, 04:06 PM
pbs's Avatar
pbs pbs is offline
Member
 
Join Date: Jan 2015
Posts: 32
Default

It works but ONLY for one product id.

So in my example (with fictional product id's), only the first in row 3432333 outputs Qty 5.
3432332 and 4543212 have no effect and outputs 1.

Thank you...

Last edited by Th sp; 09-01-2015 at 08:55 PM.
  #13  
Old 02-18-2015, 07:29 PM
enot's Avatar
enot enot is offline
 
Join Date: Oct 2014
Posts: 499
Default

Quote:
Originally Posted by Th sp View Post
Hi,

Thanks!

Now it works but ONLY for one product id.

So in my example (with fictional product id's), only the first in row 3432333 outputs Qty 5.
3432332 and 4543212 have no effect and outputs 1.

Any clue?
Thank you very much for pointing this out, it looks like I make a pretty bad tester =/
(and this is one of the reasons why we prefer to leave this to professionals).

Yet, in this case it can be fixed by creating and using an array to keep and check product ID's (plus this would prove extremely helpful when you'll have more of such products).

Here's the code that's going to work (I've also updated it in my previous posts):

Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
if (typeof(Ecwid) == 'object') {
Ecwid.OnPageLoaded.add(function(page) {
var pids = [3432333, 3432332, 4543212];
if ('PRODUCT' == page.type)
for(var i=0; i<pids.length; i++) {
if (pids[i]==page.productId)
{
$('input.ecwid-productBrowser-details-qtyTextField').val('5');
}
}
});
}
</script>
Also, it can be found here: http://pastebin.com/67GYtGAn
And product ID's can be added or changed inside the array. (the var pids = [3432333, 3432332, 4543212]; line)
  #14  
Old 02-19-2015, 05:27 PM
pbs's Avatar
pbs pbs is offline
Member
 
Join Date: Jan 2015
Posts: 32
Default

Hi Stephan,

This does the trick! Works fine now.
Thank you very much!
  #15  
Old 11-08-2015, 09:08 AM
TruVisionOfTruYou's Avatar
TruVisionOfTruYou TruVisionOfTruYou is offline
Junior Member
 
Join Date: May 2015
Posts: 4
Default

To add a maximum order requirement per product would be great as well! Is this part fixed by ecwid??
  #16  
Old 11-12-2015, 07:34 AM
Cyril D's Avatar
Cyril D Cyril D is offline
Ecwid Team
 
Join Date: Feb 2015
Location: Ecwid HQ
Posts: 530
Default

Hello,

Thanks for contacting us!

As was already mentioned in this thread, while there's no such built-in functionality in Ecwid, you can specify the minimum and maximum quantity for a particular product by means of some JS codes and Ecwid JS API.

I've updated the previous JS code and added the ability to specify the min and max values for the product quantity—use the $minValue and $maxValue variables for this. Please, mind that I'm not a professional programmer and all the codes are provided as is.

Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
if (typeof(Ecwid) == "object") {
    Ecwid.OnPageLoaded.add(function(page) {
        var $productIds = [47856077, 47856078, 47856079];
        if (page.type == "PRODUCT")
            for (var i = 0; i < $productIds.length; i++) {
                if ($productIds[i] == page.productId) {

                    $minValue = 5;
                    $maxValue = 10;
                    $oldValue = $minValue;
                    $quantityFieldClassname = "input.ecwid-productBrowser-details-qtyTextField";

                    $($quantityFieldClassname).val($minValue);

                    $($quantityFieldClassname).on("input", function() {
                        $currentQuantityFieldValue = $(this).val();

                        if ($currentQuantityFieldValue < $minValue || $currentQuantityFieldValue > $maxValue)
                        {
                            $(this).val($oldValue);
                            return false;
                        } else
                            $oldValue = $(this).val();
                    });
                }
            }
    });
}
</script>
Also, pay attention to the red magic numbers in brackets—they are IDs of products to which you want to apply this script. How to get these IDs? We have an article on this, please, take a look.

In case you need to apply this code to all products, you can use a simplified version of the above code:

Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
    if (typeof(Ecwid) == "object") {
        Ecwid.OnPageLoaded.add(function(page) {
            if (page.type == "PRODUCT") {

                $minValue = 5;
                $maxValue = 10;
                $oldValue = $minValue;
                $quantityFieldClassname = "input.ecwid-productBrowser-details-qtyTextField";

                $($quantityFieldClassname).val($minValue);

                $($quantityFieldClassname).on("input", function() {
                    $currentQuantityFieldValue = $(this).val();

                    if ($currentQuantityFieldValue < $minValue || $currentQuantityFieldValue > $maxValue) {
                        $(this).val($oldValue);
                        return false;
                    } else
                        $oldValue = $(this).val();
                });

            }
        });
    }
</script>
To make these codes work, simply add it just below the Ecwid integration code aka the Product Browser.

By the way, now users on paid plans are able to add custom JS codes to their Starter Sites—thanks to smartMart who'd created an app that allows adding custom JS/CSS codes to all Ecwid storefronts right in the control panel. The app called "Custom JS/CSS Injector" and it's in beta currently, but it works just fine—I've tried it myself. You can drop smarMart a message via DM or email and them for a beta access.

Hope this helps!
__________________
Cyril D.
Ecwid Customer Care Team

More tips and hints on Ecwid use in our Help Center

⬇ Please click Thanks if my reply helped you.

Last edited by Cyril D; 11-12-2015 at 09:57 PM.
  #17  
Old 11-12-2015, 12:27 PM
TruVisionOfTruYou's Avatar
TruVisionOfTruYou TruVisionOfTruYou is offline
Junior Member
 
Join Date: May 2015
Posts: 4
Thumbs up

Thank you. Great help!
The Following User Says Thank You to TruVisionOfTruYou For This Useful Post:
Cyril D (11-12-2015)
 
The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.

Tags
box, product, quantity

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:22 AM.
Powered by vBulletin® Version 3.8.11. Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.