Reputation: 23
I am trying to integrate SimpleScriptJS v3 in a Force.com visualforce page. I am able to query products from Salesforce and show them using SimpleCartJS class params. Products are correctly added to the cart and empty, remove, increment and decrement links works perfectly. I dont need to checkout to PayPal, google, etc. What I need is to create records into some object directly on salesforce when user clics on "ckeckout" button, so I need to get all items in cart in order to iterate and and use info to create records in Salesforce.
This is my visualforce page:
<script src="{!$Resource.ShoppingCart_SimpleCart_JS}" type="text/javascript"/>
<script src="{!$Resource.ShoppingCart_JQuery_JS}" type="text/javascript"/>
<apex:pageBlock >
<apex:repeat value="{!existingProducts}" var="wrapper">
<apex:outputPanel layout="block" style="float:left;padding-top:10px;padding-left:10px" styleClass="simpleCart_shelfItem">
<apex:image value="/servlet/servlet.FileDownload?file={!wrapper.imageId}" width="150" height="150"/>
<apex:outputPanel layout="block" style="text-align:center">
<apex:outputText value="{!wrapper.product.Name}" styleClass="item_name"/><br/>
<apex:outputText value="Price: ${!wrapper.price}" styleClass="item_price"/><br/>
<apex:outputLink value="javascript:;" styleClass="item_add">Add to Cart</apex:outputLink><br/><br/>
</apex:outputPanel>
</apex:outputPanel>
</apex:repeat>
<apex:outputPanel layout="block" style="float:right;padding-top:10px;padding-right:10px">
<apex:outputPanel styleClass="simpleCart_quantity"></apex:outputPanel>
items -
<apex:outputPanel styleClass="simpleCart_total"></apex:outputPanel>
<apex:outputPanel styleClass="simpleCart_items" layout="block"></apex:outputPanel>
<apex:outputLink value="javascript:;" styleClass="simpleCart_checkout">Checkout </apex:outputLink>
<apex:outputLink value="javascript:;" styleClass="simpleCart_empty"> Empty Cart</apex:outputLink>
</apex:outputPanel>
<apex:pageBlockButtons >
<apex:commandButton value="Checkout" action="{!checkout}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
As i said, items are correctly added and shown into the cart (my output panel with the styleClass="simpleCart_items" property).
The question is, how can i put all cart items into an array or something in order to iterate it and use them.
Can anyone help me on this?
Thanks a lot!!!
Regards!
Upvotes: 1
Views: 2419
Reputation: 1231
You can get the items array using the SimpleCart object:
simpleCart.each(function(item){
console.log( item.get('quantity') + ' x ' + item.get('name') );
});
Alternatively, you can submit the form to a custom script using the .sendForm method.
Upvotes: 2