{"id":60360,"date":"2025-04-24T10:01:07","date_gmt":"2025-04-24T02:01:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/60360\/"},"modified":"2025-04-24T10:01:07","modified_gmt":"2025-04-24T02:01:07","slug":"ecshop%e5%95%86%e5%93%81%e5%b1%9e%e6%80%a7%e6%8e%92%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/60360\/","title":{"rendered":"ecshop\u5546\u54c1\u5c5e\u6027\u6392\u5e8f\u7684\u95ee\u9898"},"content":{"rendered":"<p>&nbsp;     &nbsp;    <\/p>\n<table cellpadding=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td> \u60c5\u51b5\u4e00\uff1a\u6dfb\u52a0\u65b0\u4ea7\u54c1\u65f6\uff0c\u8ba9<span>\u5c5e\u6027<\/span>\u6309\u7167\u6dfb\u52a0\u7684\u987a\u5e8f\uff08\u5c5e\u6027id\uff09\u6392\u5217<br \/> \u4fee\u6539\/inclues\/lib_goods.php<\/p>\n<p> &nbsp; &nbsp; \/* \u83b7\u5f97<span>\u5546\u54c1<\/span>\u7684\u89c4\u683c *\/<br \/> &nbsp; &nbsp; $sql = &#8220;SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type, &#8220;.<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &#8220;g.goods_attr_id, g.attr_value, g.attr_price &#8221; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods_attr&#8217;) . &#8216; AS g &#8216; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;LEFT JOIN &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;attribute&#8217;) . &#8216; AS a ON a.attr_id = g.attr_id &#8216; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8220;WHERE g.goods_id = &#8216;$goods_id&#8217; &#8221; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font>&#8216;ORDER BY g.goods_attr_id, a.sort_order, g.attr_price&#8217;<\/font>;<br \/> &nbsp; &nbsp; $res = $GLOBALS[&#8216;db&#8217;]-&gt;getAll($sql);<\/p>\n<p> \u60c5\u51b5\u4e8c\uff1a\u5728\u590d\u5236\u5546\u54c1\u65f6<strong><font>\u5c5e\u6027\u6392\u5e8f<\/font><\/strong>\u8ddf\u539f\u5546\u54c1\u76f8\u53cd\u5230\u5904\u7406<br \/> \u4fee\u6539\/inclues\/lib_goods.php<br \/> \/**<br \/> * \u53d6\u5f97\u5546\u54c1\u5c5e\u6027<br \/> * @param&nbsp; &nbsp;int&nbsp; &nbsp;&nbsp;&nbsp;$goods_id&nbsp; &nbsp;\u5546\u54c1id<br \/> * @return&nbsp;&nbsp;array<br \/> *\/<br \/> function get_goods_attr($goods_id)<br \/> {<br \/> &nbsp; &nbsp; $attr_list = array();<br \/> &nbsp; &nbsp; $sql = &#8220;SELECT a.attr_id, a.attr_name &#8221; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8220;FROM &#8221; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods&#8217;) . &#8221; AS g, &#8221; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;attribute&#8217;) . &#8221; AS a &#8221; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8220;WHERE g.goods_id = &#8216;$goods_id&#8217; &#8221; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8220;AND g.goods_type = a.cat_id &#8221; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8220;AND a.attr_type = 1&#8221;.&#8217; ORDER BY a.attr_id&#8217;;<br \/> &nbsp; &nbsp; $attr_id_list = $GLOBALS[&#8216;db&#8217;]-&gt;getCol($sql);<br \/> &nbsp; &nbsp; $res = $GLOBALS[&#8216;db&#8217;]-&gt;query($sql);<br \/> &nbsp; &nbsp; while ($attr = $GLOBALS[&#8216;db&#8217;]-&gt;fetchRow($res))<br \/> &nbsp; &nbsp; {<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (defined(&#8216;ECS_ADMIN&#8217;))<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$attr[&#8216;goods_attr_list&#8217;] = array(0 =&gt; $GLOBALS[&#8216;_LANG&#8217;][&#8216;select_please&#8217;]);<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$attr[&#8216;goods_attr_list&#8217;] = array();<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$attr_list[$attr[&#8216;attr_id&#8217;]] = $attr;<br \/> &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; $sql = &#8220;SELECT attr_id, goods_attr_id, attr_value &#8221; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8220;FROM &#8221; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods_attr&#8217;) .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8221; WHERE goods_id = &#8216;$goods_id&#8217; &#8221; .<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8220;AND attr_id &#8221; . db_create_in($attr_id_list)<font>.&#8217; ORDER BY goods_attr_id&#8217;<\/font>;<br \/> &nbsp; &nbsp; $res = $GLOBALS[&#8216;db&#8217;]-&gt;query($sql);<br \/> &nbsp; &nbsp; while ($goods_attr = $GLOBALS[&#8216;db&#8217;]-&gt;fetchRow($res))<br \/> &nbsp; &nbsp; {<br \/> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$attr_list[$goods_attr[&#8216;attr_id&#8217;]][&#8216;goods_attr_list&#8217;][$goods_attr[&#8216;goods_attr_id&#8217;]] = $goods_attr[&#8216;attr_value&#8217;];<br \/> &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; return $attr_list;<br \/> }<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p> \u8865\u5145\uff1a\u4e0a\u9762\u8bf4\u7684\u662f\u540c\u4e00\u5c5e\u6027\u91cc\u5c5e\u6027\u503c\u7684\u6392\u5e8f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; \u60c5\u51b5\u4e00\uff1a\u6dfb\u52a0\u65b0\u4ea7\u54c1\u65f6\uff0c\u8ba9\u5c5e\u6027\u6309\u7167\u6dfb\u52a0\u7684\u987a\u5e8f\uff08\u5c5e\u6027id\uff09\u6392\u5217 \u4fee\u6539\/inclues\/lib_goods.php &nbsp; &nbsp; \/* \u83b7\u5f97\u5546\u54c1\u7684\u89c4\u683c *\/ &nbsp; &nbsp; $sql = &#8220;SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type, &#8220;. &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &#8220;g.goods_attr_id, g.attr_value, g.attr_price &#8221; . &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods_attr&#8217;) . &#8216; AS g &#8216; . &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;LEFT JOIN &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;attribute&#8217;) . [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-60360","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=60360"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60360\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=60360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=60360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=60360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}