【问题标题】:SimpleCart.js - add shipping information to objectSimpleCart.js - 向对象添加运输信息
【发布时间】:2014-08-21 21:11:31
【问题描述】:

我正在将 SimpleCart.js (http://simplecartjs.org/) 集成到一个小项目中。我想看看是否可以将运输信息实际添加到 SimpleCart 对象中。

我从现有的用户帐户中获取了发货信息,其中包含:

shipId、ship_first、ship_last、ship_street、ship_city、ship_state、ship_zip、ship_phone

我在文档中看到我可以扩展 SimpleCart.js 对象 (http://simplecartjs.org/documentation/simplecart-extend)。所以目前我正在这样做:

在我的 HTML 标记中:

<a href="#" onclick="setShipping(<?php echo $address['id'] . ", '" . $address['ship_first'] [...] ?>Set Address</a>

我的 javascript 看起来像这样:

<script>
    function setShipping(shipId, ship_first [...]) {
        var shippingInfo = {
             shipId: shipId,
             ship_first: ship_first,
             [...]
        };

    simpleCart.extend(simpleCart, shippingInfo); 

   // do some more stuff like updating the checkout button and tax rate
  }
 </script>

此代码在此页面上有效,但是当我浏览到另一个页面时,运输属性似乎丢失了。我基本上会在每个页面上检查是否设置了送货,如果没有,我会显示设置送货地址的链接。

如何“永久”扩展对象?

【问题讨论】:

  • 我浏览到另一个页面,该页面是否有 Simplecart 对象是该页面上的扩展脚本?
  • 我不确定我是否理解您的评论,@VeeeneX。
  • 哦,对不起,我忘了检查它。所以你在其他页面上没有那个脚本?这些属性是否保存在 LocalStorage 中?
  • 没错。 SimpleCart 存储在本地存储中,扩展对象的脚本仅在一页上。

标签: javascript jquery simplecart


【解决方案1】:

只需将您的 simpleCart 扩展程序添加到实际的 simpleCart.js 文件中即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-10
    • 2023-03-15
    • 1970-01-01
    • 2019-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    相关资源
    最近更新 更多