SilverCart Forum
We moderate this Forum and we're here to help. Have you already run a forum search to check if your problem has already been solved?
You can help us helping you by providing detailed error messages, screenshots and logfile entries.
Page: 1 | ||
Topic Adding more than 999 to the Cart | 3240 Views |
Adding more than 999 to the Cart
11 April 2013 at 7:33am Last edited: 11 April 2013 7:35amHi,
Under the Configuration I have set the "Maximum allowed quantity of a single product in the shopping cart" to 9999. However, under the Product "Add to cart" field it won’t let me enter more than 3 digits, i.e., no more than 999. I can add the quantity in several goes to get above this amount in the Cart, but what do need I to edit to remove this restriction under the Product? Is this being checked via a (Java)script for example?
Thanks very much.
Graeme
Re: Adding more than 999 to the Cart
11 April 2013 at 9:27amHello Graeme,
currently the "add to cart" forms use a hard coded value of 3 digits instead of this setting.
This error got fixed today; it will be available with the next SilverCart release (1.3.7.1 or 1.3.8).
If you don't want to wait for that release you can replace the method "preferences" in "silvercart/code/custom_forms/SilvercartProductAddCartForm.php" with the following code:
public function preferences() {
$numberOfDecimalPlaces = false;
if ($this->getProduct()->isInCart()) {
$this->preferences['submitButtonTitle'] = _t('SilvercartProduct.CHANGE_QUANTITY_CART');
} else {
$this->preferences['submitButtonTitle'] = _t('SilvercartProduct.ADD_TO_CART');
}
$this->preferences['doJsValidationScrolling'] = false;
$this->formFields['productQuantity']['title'] = _t('SilvercartProduct.QUANTITY');
$this->setCustomParameter('backLink', Controller::curr()->Link());
// Get maxlength for quantity field
$quantityFieldMaxLength = strlen((string) SilvercartConfig::addToCartMaxQuantity());
if ($quantityFieldMaxLength == 0) {
$quantityFieldMaxLength = 1;
}
if (array_key_exists('productID', $this->customParameters)) {
$silvercartProduct = $this->getProduct();
if ($silvercartProduct instanceof SilvercartProduct) {
$numberOfDecimalPlaces = $silvercartProduct->SilvercartQuantityUnit()->numberOfDecimalPlaces;
}
}
if ($numberOfDecimalPlaces !== false &&
$numberOfDecimalPlaces > 0) {
if (array_key_exists('isNumbersOnly', $this->formFields['productQuantity']['checkRequirements'])) {
unset($this->formFields['productQuantity']['checkRequirements']['isNumbersOnly']);
}
$this->formFields['productQuantity']['checkRequirements']['isDecimalNumber'] = $numberOfDecimalPlaces;
$this->formFields['productQuantity']['maxLength'] = $quantityFieldMaxLength + 1 + $numberOfDecimalPlaces;
} else {
$this->formFields['productQuantity']['maxLength'] = $quantityFieldMaxLength;
}
}
Thanks for reporting :)
Greetings,
Sascha
Re: Adding more than 999 to the Cart
22 April 2013 at 5:19amHi Sascha,
My installation (1.3.6) doesn’t like this part:
if (array_key_exists('productID', $this->customParameters)) {
$silvercartProduct = $this->getProduct();
if ($silvercartProduct instanceof SilvercartProduct) {
$numberOfDecimalPlaces = $silvercartProduct->SilvercartQuantityUnit()->numberOfDecimalPlaces;
}
}
(I have left the existing code in place for this section.)
However, even with hard coding
$this->formFields['productQuantity']['maxLength'] = 5
it still won’t let me add more than 999. Is there some Javascript validation going on?
Graeme
Re: Adding more than 999 to the Cart
24 April 2013 at 11:18amHello Graeme,
with my 1.3.7 installation this setting works just fine.
If the problem still occurs after an upgrade to SilverCart 1.3.7 you should try to empty the caches (delete all contents in directory "silverstripe-cache/").
Greetings,
Sascha
Re: Adding more than 999 to the Cart
24 April 2013 at 12:39pmHi Sascha,
You’re right—works fine after upgrade to 1.3.7
One more question: how do I increase the field width to accommodate the extra digits allowed? I tried, for testing purposes, in the same file and function (preferences):
$this->formFields['productQuantity']['size'] = 7;
Didn't work, unfortunately.
Graeme
Re: Adding more than 999 to the Cart
24 April 2013 at 12:48pmHi Graeme,
glad to hear that it works now :)
The "add to cart" field width is set via CSS in the files
- "/silvercart/css/screen/custom/SilvercartProductGroupPageTile.css" line 35: for the tile views
- "/silvercart/css/screen/custom/SilvercartProductGroupPageList.css" line 36: for the list views
- "/silvercart/css/screen/custom/SilvercartProductPage.css" line 80: for the detail view
In order to adjust the size you would have to overwrite those CSS rules in your custom stylesheet.
If you want to use the size attribute you should set the widths to "auto".
Greetings,
Sascha
Re: Adding more than 999 to the Cart
24 April 2013 at 12:54pmHi Sascha,
Makes sense.
Thanks for the help.
Graeme
Re: Adding more than 999 to the Cart
24 April 2013 at 12:55pmYour welcome :)