{"id":199336,"date":"2025-05-03T13:23:11","date_gmt":"2025-05-03T05:23:11","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199336\/"},"modified":"2025-05-03T13:23:11","modified_gmt":"2025-05-03T05:23:11","slug":"%e8%8e%b7%e5%8f%96ecshop%e5%90%84%e4%b8%aa%e5%b1%9e%e6%80%a7%e7%9a%84%e5%ba%93%e5%ad%98%e7%9a%84%e7%ae%80%e5%8d%95%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199336\/","title":{"rendered":"\u83b7\u53d6Ecshop\u5404\u4e2a\u5c5e\u6027\u7684\u5e93\u5b58\u7684\u7b80\u5355\u65b9\u6cd5"},"content":{"rendered":"<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> \u539f\u7406\uff1a\u4eceecshop\u6570\u636e\u5e93\u63d0\u53d6\u5404\u4e2a\u5c5e\u6027\u7684\u5e93\u5b58\uff0c\u653e\u5230\u4e00\u4e2a\u51fd\u6570\u91cc\uff0c\u7136\u540e\u7528\u6a21\u677f\u8c03\u7528\u51fa\u6765\u3002<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> \u9700\u8981\u4fee\u6539\u7684ecshop\u6587\u4ef6\uff1a<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> 1.\u4e3b\u9898\u6a21\u677fgoods.dwt<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> 2.includes\u4e0b\u7684lib_goods.php<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> &nbsp;<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> <strong>Step 1.<\/strong><\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> \u4fee\u6539goods.dwt<\/p>\n<blockquote style=\"width: 600px;line-height: 23px;margin: 5px auto;padding: 10px;clear: both;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;font-size: 14px\">\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;text-indent: 2em;background: transparent\"> \u5728294\u884c\u5de6\u53f3\uff0c&nbsp; &lt;!&#8211; {foreach from=$spec.values item=value key=key} &#8211;&gt;\u548c&nbsp;&nbsp; &nbsp;&lt;!&#8211; {\/foreach} &#8211;&gt;\u4e4b\u95f4\uff0c\u589e\u52a0\uff08\u5e93\u5b58\uff1a{$value.product_number} {$goods.measure_unit}\uff09<\/p>\n<\/blockquote>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> &nbsp;<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> <strong>Step 2.<\/strong><\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> \u4fee\u6539includes\u4e0b\u7684lib_goods.php<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> \u5728625\u884c\/* \u83b7\u5f97\u5546\u54c1\u7684\u89c4\u683c *\/\u4e2d\uff0c\u4fee\u6539\u6210\u5982\u4e0b\u6837\u5b50\uff1a\u7ea2\u8272\u90e8\u5206\u662f\u589e\u52a0\u7684\u8c03\u7528<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> &nbsp;<\/p>\n<blockquote style=\"width: 600px;line-height: 23px;margin: 5px auto;padding: 10px;clear: both;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;font-size: 14px\">\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;text-indent: 2em;background: transparent\"> $sql = &#8220;SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type, &#8220;.<br \/> &#8220;g.goods_attr_id, g.attr_value, g.attr_price &#8221; .<span style=\"margin: 0px;padding: 0px;border: 0px;background: transparent\">&nbsp;&#8220;,p.product_sn,p.product_number &#8221; .<\/span><br \/> &#8216;FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods_attr&#8217;) . &#8216; AS g &#8216; .<br \/> &#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 \/> <span style=\"margin: 0px;padding: 0px;border: 0px;background: transparent\">&#8216;LEFT JOIN &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;products&#8217;) . &#8216; AS p ON g.goods_attr_id = p.goods_attr &#8216; .<\/span><br \/> &#8220;WHERE g.goods_id = &#8216;$goods_id&#8217; &#8221; .<br \/> &#8216;ORDER BY a.sort_order, g.attr_price, g.goods_attr_id&#8217;;<br \/> $res = $GLOBALS[&#8216;db&#8217;]-&gt;getAll($sql);<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;text-indent: 2em;background: transparent\"> $arr[&#8216;pro&#8217;] = array(); \/\/ \u5c5e\u6027<br \/> $arr[&#8216;spe&#8217;] = array(); \/\/ \u89c4\u683c<br \/> $arr[&#8216;lnk&#8217;] = array(); \/\/ \u5173\u8054\u7684\u5c5e\u6027<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;text-indent: 2em;background: transparent\"> foreach ($res AS $row)<br \/> {<br \/> $row[&#8216;attr_value&#8217;] = str_replace(&#8220;\\n&#8221;, &#8216;&lt;br \/&gt;&#8217;, $row[&#8216;attr_value&#8217;]);<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;text-indent: 2em;background: transparent\"> if ($row[&#8216;attr_type&#8217;] == 0)<br \/> {<br \/> $group = (isset($groups[$row[&#8216;attr_group&#8217;]])) ? $groups[$row[&#8216;attr_group&#8217;]] : $GLOBALS[&#8216;_LANG&#8217;][&#8216;goods_attr&#8217;];<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;text-indent: 2em;background: transparent\"> $arr[&#8216;pro&#8217;][$group][$row[&#8216;attr_id&#8217;]][&#8216;name&#8217;] = $row[&#8216;attr_name&#8217;];<br \/> $arr[&#8216;pro&#8217;][$group][$row[&#8216;attr_id&#8217;]][&#8216;value&#8217;] = $row[&#8216;attr_value&#8217;];<br \/> }<br \/> else<br \/> {<br \/> $arr[&#8216;spe&#8217;][$row[&#8216;attr_id&#8217;]][&#8216;attr_type&#8217;] = $row[&#8216;attr_type&#8217;];<br \/> $arr[&#8216;spe&#8217;][$row[&#8216;attr_id&#8217;]][&#8216;name&#8217;] = $row[&#8216;attr_name&#8217;];<br \/> $arr[&#8216;spe&#8217;][$row[&#8216;attr_id&#8217;]][&#8216;values&#8217;][] = array(<br \/> &#8216;label&#8217; =&gt; $row[&#8216;attr_value&#8217;],<br \/> &#8216;price&#8217; =&gt; $row[&#8216;attr_price&#8217;],<br \/> &#8216;format_price&#8217; =&gt; price_format(abs($row[&#8216;attr_price&#8217;]), false),<br \/> &#8216;id&#8217; =&gt; $row[&#8216;goods_attr_id&#8217;],<br \/> <span style=\"margin: 0px;padding: 0px;border: 0px;background: transparent\">&#8216;product_sn&#8217; =&gt; $row[&#8220;product_sn&#8221;],<\/span><br \/> <span style=\"margin: 0px;padding: 0px;border: 0px;background: transparent\">&#8216;product_number&#8217; =&gt; $row[&#8220;product_number&#8221;]);<\/span><br \/> }<\/p>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;text-indent: 2em;background: transparent\"> &nbsp;<\/p>\n<\/blockquote>\n<p style=\"margin: 0px 0px 10px;padding: 0px;border: 0px;font-size: 13px;text-indent: 2em;line-height: 32.5px;background-image: initial;background-attachment: initial;background-size: initial;background-position: initial;background-repeat: initial\"> &nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u7406\uff1a\u4eceecshop\u6570\u636e\u5e93\u63d0\u53d6\u5404&#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-199336","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199336","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=199336"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199336\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}