{"id":199094,"date":"2025-05-03T13:43:52","date_gmt":"2025-05-03T05:43:52","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199094\/"},"modified":"2025-05-03T13:43:52","modified_gmt":"2025-05-03T05:43:52","slug":"ecshop%e8%b4%ad%e7%89%a9%e8%bd%a6%e6%97%a0%e5%88%b7%e6%96%b0%e6%9b%b4%e6%96%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199094\/","title":{"rendered":"ecshop\u8d2d\u7269\u8f66\u65e0\u5237\u65b0\u66f4\u65b0"},"content":{"rendered":"<p>&nbsp;ecshop<span style=\"font-family: Verdana, Arial, Tahoma;line-height: 25px\"><strong>\u7684\u8d2d\u7269\u8f66<\/strong>\u4f7f\u7528\u662f\u76f8\u5f53\u7684\u4e0d\u65b9\u4fbf\uff0eecshop\u8d2d\u7269\u8f66\u4e00\u65e6\u52a0\u5165\u4e86\u5546\u54c1\uff0c\u5c31\u5fc5\u987b\u70b9\u66f4\u65b0\u6570\u91cf\u7684\u6309\u626d\u624d\u80fd\u591f\u66f4\u65b0\uff0e\u8fd9\u6837\u5bf9ecshop\u4f7f\u7528\u8005\u76f8\u5f53\u7684\u4e0d\u65b9\u4fbf\u3002\u6211\u4eec\u5c06\u7ed3\u5408ecshop ajax\u7684\u601d\u8def\u3002\u6765\u8bb2\u8bb2\u7528ecshop\u7684ajax\u65e0\u5237\u65b0\u66f4\u65b0\u8d2d\u7269\u8f66. <\/span><\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;&nbsp;&nbsp; 1:\u9996\u5148\u8981\u5305\u542bjs\/shopping_flow.js \u8be5\u6587\u4ef6\u4e3b\u8981\u662f\u9488\u5bf9ecshop\u8d2d\u4e70\u6d41\u7a0b\u63a7\u5236\u7684js.\u6211\u4eec\u5c06\u589e\u52a0\u4ee5\u4e0b\u51fd\u6570\uff0e<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;&nbsp;&nbsp; function submit_update_cart(rec_id){<br \/> &nbsp;var goods_number = document.getElementById(&#8220;goods_number_&#8221;+rec_id).value;<br \/> &nbsp;<br \/> &nbsp;Ajax.call(&#8216;flow.php?step=ajax_update_cart&#8217;, &#8216;goods_number=&#8217; + goods_number+&#8217;&amp;rec_id=&#8217;+rec_id, submit_update_cartResponse_cart, &#8216;GET&#8217;, &#8216;JSON&#8217;);<br \/> &nbsp;}<br \/> &nbsp;<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;&nbsp; 2:\u5728flow.dwt\u4e2d\u3002\u6211\u4eec\u8981\u4fee\u6539input\u8f93\u5165\u6846\uff0e&lt;input type=&#8221;text&#8221; name=&#8221;goods_number[{$goods.rec_id}]&#8221; id=&#8221;goods_number_{$goods.rec_id}&#8221;<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;&nbsp; 3:\u5728ecshop\u7684\u8d2d\u7269\u8f66\u51fd\u6570\u4e2d\u3002\u4ec0\u4e48json\u6765\u7ed3\u5408ecshop ajax\u5904\u7406\u66f4\u65b0\u7ed3\u679c\uff0e\u90e8\u5206\u7a0b\u5e8f\u5982\u4e0b<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;&nbsp; include_once(&#8216;includes\/cls_json.php&#8217;);<br \/> &nbsp;&nbsp;&nbsp; $result = array(&#8216;error&#8217; =&gt; &#8221;, &#8216;content&#8217; =&gt; &#8221;, &#8216;fanliy_number&#8217; =&gt; &#8216;0&#8217;, &#8216;rec_id&#8217; =&gt; &#8221;);<br \/> &nbsp;$json = new JSON();<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;\/* AJAX\u4fee\u6539\u8d2d\u7269\u8f66 *\/<br \/> &nbsp;$rec_id&nbsp;&nbsp;&nbsp;= $_REQUEST[&#8216;rec_id&#8217;]; \/\/\u8d2d\u7269\u8f66ID<br \/> &nbsp;$goods_number&nbsp;&nbsp; = $_REQUEST[&#8216;goods_number&#8217;];\/\/<br \/> &nbsp;<br \/> &nbsp;&nbsp;&nbsp;<br \/> &nbsp;\/* \u5224\u65ad\u5e93\u5b58 *\/<br \/> &nbsp;$num = $db -&gt; getOne(&#8220;select g.goods_number from &#8220;.$ecs-&gt;table(&#8216;goods&#8217;).&#8221; g ,&#8221;.$ecs-&gt;table(&#8216;cart&#8217;).&#8221; c where c.rec_id = &#8216;$rec_id&#8217; and g.goods_id = c.goods_id &#8220;);<br \/> &nbsp;if($goods_number &gt; $num){<br \/> &nbsp;&nbsp;$goods_number = $num;<br \/> &nbsp;&nbsp;$result[&#8216;error&#8217;]&nbsp;&nbsp;= 1;<br \/> &nbsp;&nbsp;$result[&#8216;fanliy_number&#8217;]= $num;<br \/> &nbsp;&nbsp;$result[&#8216;rec_id&#8217;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = $rec_id;<br \/> &nbsp;&nbsp;$result[&#8216;content&#8217;]&nbsp;&nbsp;= &#8216;\u8be5\u5546\u54c1\u5e93\u5b58\u4e0d\u8db3&#8217;.$goods_number.&#8221; \u4ef6,\u53ea\u6709&#8221;.$num.&#8221;\u4ef6&#8221;;<br \/> &nbsp;&nbsp;die($json-&gt;encode($result));<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;}<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\"> &nbsp;\/* \u4fee\u6539\u5546\u54c1\u8d2d\u7269\u8f66 *\/<br \/> &nbsp;$sql = &#8220;update &#8220;.$ecs-&gt;table(&#8216;cart&#8217;).&#8221; set goods_number = &#8216;&#8221;.$goods_number.&#8221;&#8216; where rec_id = &#8216;&#8221;.$rec_id.&#8221;&#8216; and session_id = &#8216;&#8221; . SESS_ID . &#8220;&#8216; &#8220;;<br \/> &nbsp;$db -&gt; query($sql);<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;&nbsp;&nbsp; 4:\u901a\u8fc7flow.php\u4e2d\u7684php\uff0e\u8fd4\u56de\u66f4\u65b0\u6570\u91cf\u540e\u7684\u7ed3\u679c\uff0e<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;&nbsp; function submit_update_cartResponse_cart(result){<br \/> &nbsp;&nbsp;&nbsp;&nbsp;<br \/> &nbsp;if(result.error == &#8216;1&#8217;){<br \/> &nbsp;&nbsp;document.getElementById(&#8220;goods_number_&#8221;+result.rec_id).value = result.fanliy_number;<br \/> &nbsp;&nbsp;alert(result.content)<br \/> &nbsp;}else{<br \/> &nbsp;&nbsp;var layer = document.getElementById(&#8220;xianshi_price&#8221;);<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/> &nbsp;&nbsp;layer.innerHTML = (typeof result == &#8220;object&#8221;) ? result.content : result;<br \/> &nbsp;}<br \/> &nbsp;}<\/p>\n<p style=\"padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px\">&nbsp;&nbsp;&nbsp; \u901a\u8fc7\u4ee5\u4e0aecshop\u4e8c\u6b21\u5f00\u53d1\u4f8b\u5b50\uff0c\u6211\u4eec\u597d\u6a21\u677f\u5b8c\u6210\u4e86ecshop\u8d2d\u7269\u8f66\u65e0\u5237\u65b0\u66f4\u65b0\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;ecshop\u7684\u8d2d\u7269\u8f66&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-199094","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=199094"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199094\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}