Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

ajaxQuantityField


Go to End


3 Posts   1512 Views

Avatar
janulka

Community Member, 80 Posts

5 January 2012 at 9:36am

Hello,

ajaxQuantityField is not working properly for me..

on Checkout/Cart page:
when customer changes quantity by typing in the text field, it is sent to server (e.g..../shoppingcart/setquantityitem/235?quantity=25), but the total price is not updated until I manually refresh the page

on Product page:
when changing quantity here by typing in the field, absolutely nothing happens..

can someone help me with this?

is there possibility for customers to change quantity already when purchasing items, what I mean is to have small text field next to "purchase" button, so they can buy 5 items straight away instead of having to change quantity in cart afterwards?

Thank you!

Avatar
janulka

Community Member, 80 Posts

11 January 2012 at 12:39am

Well, I have to remove quantity field from Product.ss and ProductGroupItem.ss since I have no idea how to get this work.

On Cart.ss, I have added onchange window.location.reload() this way:

function Field() {
		$size = 3; //make these customisable
		$maxlength = 3;

		$attributes = array(
			'type' => 'text',
			'class' => implode(' ',$this->classes),
			'name' => $this->item->MainID() . '_Quantity',
			'value' => ($this->item->Quantity) ? $this->item->Quantity : "",
			'maxlength' => $maxlength,
			'size' => $size ,
			'disabled' => 'disabled',
			'onchange' => "window.location.reload();"
		);
		
		//IMPROVE ME: hack to use the form field createTag method ...perhaps this should become a form field instead
		$formfield = new FormField('hack'); 
		return $formfield->createTag('input', $attributes);
	}

This works - sometimes.. When the server is fast enough to response with quantity update, then it is updated, when it is not fast enough to respond, the page is reloaded without quantity update.

Plz, I seriously really need help , now with javascript function how to make javascript wait for server response, and then reload page - after the quantity has been sent to server..

Avatar
janulka

Community Member, 80 Posts

11 January 2012 at 1:22am

and in addition to that, huuge issue with variations, this code:

function AJAXLinkHiddenField(){
		if($quantitylink = ShoppingCart::set_quantity_item_link($this->item->getProductVariationIDForSerialization(), null,$this->parameters)){
			$attributes = array(
				'type' => 'hidden',
				'class' => 'ajaxQuantityField_qtylink',
				'name' => $this->item->MainID() . '_Quantity_SetQuantityLink',
				'value' => $quantitylink
			);
			$formfield = new FormField('hack'); 
			return $formfield->createTag('input', $attributes);
		}
	}

is creating link to change quantity of the productID rather than productVariationID, lets say i have product 200 with variations 55 and 56, changing quantity for both with this server response:

shoppingcart/setquantityitem/200?quantity=XX , what means that only first variation is changed no matter what!