SimpleCartJS - 如何获取购物车中的所有商品?

时间:2012-06-04 07:48:13

标签: javascript salesforce visualforce force.com

我正在尝试在Force.com visualforce页面中集成SimpleScriptJS v3。 我能够从Salesforce查询产品并使用SimpleCartJS类参数显示它们。 产品正确添加到购物车中,清空,移除,增加和减少链接完美地工作。 我不需要结账到PayPal,谷歌等。我需要的是当用户在“ckeckout”按钮上点击时直接在salesforce上创建记录到某些对象,所以我需要获取购物车中的所有商品以便迭代和使用info在Salesforce中创建记录。

这是我的visualforce页面:

<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>

正如我所说,项目已正确添加并显示在购物车中(我的输出面板带有styleClass =“simpleCart_items”属性)。

问题是,如何将所有购物车项目放入数组或其他内容以便迭代并使用它们。

有人可以帮我吗?

非常感谢!!!

问候!

1 个答案:

答案 0 :(得分:2)

您可以使用SimpleCart对象获取items数组:

simpleCart.each(function(item){
    console.log( item.get('quantity') + ' x ' + item.get('name') );
});

或者,您可以使用.sendForm方法将表单提交到自定义脚本。