【问题标题】:SimpleCartJS - How to get all items in cart?SimpleCartJS - 如何获取购物车中的所有商品?
【发布时间】:2012-06-04 07:48:13
【问题描述】:

我正在尝试将 SimpleScriptJS v3 集成到 Force.com visualforce 页面中。 我能够从 Salesforce 查询产品并使用 SimpleCartJS 类参数显示它们。 产品已正确添加到购物车,清空、删除、递增和递减链接完美运行。 我不需要结帐到 PayPal、google 等。我需要的是当用户单击“ckeckout”按钮时直接在 salesforce 上创建记录到某个对象中,所以我需要获取购物车中的所有项目以便迭代和使用在 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" 属性)。

问题是,我怎样才能将所有购物车物品放入一个数组或其他东西中以便对其进行迭代并使用它们。

谁能帮我解决这个问题?

非常感谢!!!

问候!

【问题讨论】:

    标签: javascript salesforce visualforce force.com


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-12-09
      • 2014-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多