{"id":60247,"date":"2025-04-24T11:37:04","date_gmt":"2025-04-24T03:37:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/60247\/"},"modified":"2025-04-24T11:37:04","modified_gmt":"2025-04-24T03:37:04","slug":"%e8%ae%a9ecshop%e5%95%86%e5%93%81%e5%b1%9e%e6%80%a7%e6%98%be%e7%a4%ba%e5%8d%95%e9%80%89%e6%8c%89%e9%92%ae%e4%b8%8e%e4%b8%8b%e6%8b%89%e5%88%97%e8%a1%a8%e5%85%b1%e5%90%8c%e5%b1%95%e7%a4%ba-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/60247\/","title":{"rendered":"\u8ba9ecshop\u5546\u54c1\u5c5e\u6027\u663e\u793a\u5355\u9009\u6309\u94ae\u4e0e\u4e0b\u62c9\u5217\u8868\u5171\u540c\u5c55\u793a"},"content":{"rendered":"<p>\u6211\u4eec\u540e\u53f0\u8bbe\u5b9aecshop\u5c5e\u6027\u5217\u8868\uff0c\u5b58\u5728\u4e24\u79cd\u8bbe\u5b9a\u65b9\u5f0f\u5546\u54c1\u5c5e\u6027\u663e\u793a\u6837\u5f0f: \u5355\u9009\u6309\u94ae \u4e0e\u4e0b\u62c9\u5217\u8868\uff0c\u4f46\u662f\u6709\u65f6\u5019\u53ef\u80fd\u6211\u4eec\u9700\u8981\u8ba9ecshop\u5546\u54c1\u540c\u65f6\u652f\u6301\u4e0b\u62c9\u4e0e\u5355\u9009\u6309\u94ae\uff0c\u600e\u4e48\u529e\uff1f<\/p>\n<p> \u8fd9\u91cc\u597d\u6a21\u677f\u63d0\u4f9b\u7b80\u5355\u7684\u4e00\u4e2a\u65b9\u6cd5<\/p>\n<p> \u5728ecshop\u8bbe\u5b9a\u5c5e\u6027\u503c\u65f6\uff0c\u5982\u4e00\u822c\u5426\u8fdb\u884c\u68c0\u7d22 \uff0c\u6211\u4eec\u90fd\u4e0d\u4f1a\u9009\u62e9\uff0c\u90a3\u4e48\u53ef\u4ee5\u8bbe\u5b9a\u8d77\u6765\uff0c\u5728\u7cfb\u7edf\u5f53\u4e2d\u4ee5\u8fd9\u4e2a\u4e3a\u53c2\u7167\u6765\u5224\u65ad\u3002<br \/>\n<br \/> \u7528\u5230\u7684\u5b57\u6bb5attr_index \u503c\u4e3a1<br \/>\n<br \/> 1. \u627e\u5230\u7cfb\u7edflib_goods.php\u6587\u4ef6\uff0c\u51fd\u6570get_goods_properties\u3002\u589e\u52a0\u5c5e\u6027spe\u7684\u503c<br \/>\n<br \/> \u6b64\u6bb5\u6539\u6210\uff1a<br \/>\n<br \/>  foreach ($res AS $row) {   &nbsp; &nbsp; &nbsp; &nbsp; $row[&#8216;attr_value&#8217;] = str_replace(&#8220;\\n&#8221;, &#8216;&lt;br \/&gt;&#8217;, $row[&#8216;attr_value&#8217;]);   &nbsp;   &nbsp; &nbsp; &nbsp; &nbsp; if ($row[&#8216;attr_type&#8217;] == 0) {   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $group = (isset($groups[$row[&#8216;attr_group&#8217;]])) ? $groups[$row[&#8216;attr_group&#8217;]] : $GLOBALS[&#8216;_LANG&#8217;][&#8216;goods_attr&#8217;];   &nbsp;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[&#8216;pro&#8217;][$group][$row[&#8216;attr_id&#8217;]][&#8216;name&#8217;] = $row[&#8216;attr_name&#8217;];   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[&#8216;pro&#8217;][$group][$row[&#8216;attr_id&#8217;]][&#8216;value&#8217;] = $row[&#8216;attr_value&#8217;];   &nbsp; &nbsp; &nbsp; &nbsp; } else {   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[&#8216;spe&#8217;][$row[&#8216;attr_id&#8217;]][&#8216;attr_type&#8217;] = $row[&#8216;attr_type&#8217;];   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[&#8216;spe&#8217;][$row[&#8216;attr_id&#8217;]][&#8216;name&#8217;] = $row[&#8216;attr_name&#8217;];   $arr[&#8216;spe&#8217;][$row[&#8216;attr_id&#8217;]][&#8216;attr_index&#8217;] = $row[&#8216;attr_index&#8217;];   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[&#8216;spe&#8217;][$row[&#8216;attr_id&#8217;]][&#8216;values&#8217;][] = array(   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;label&#8217; =&gt; $row[&#8216;attr_value&#8217;],   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;price&#8217; =&gt; $row[&#8216;attr_price&#8217;],   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;format_price&#8217; =&gt; price_format(abs($row[&#8216;attr_price&#8217;]), false),   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;id&#8217; =&gt; $row[&#8216;goods_attr_id&#8217;]);   &nbsp; &nbsp; &nbsp; &nbsp; } <\/p>\n<p> 2\uff0c\u5728\u6a21\u677f\u5f53\u4e2d\u5224\u65ad<br \/>\n<br \/> <br \/>\n<span style=\"color:#ff0000\">&lt;!&#8211; {if $spec.attr_index eq 1} &#8211;&gt;<\/span>   &nbsp;&lt;!&#8211; {foreach from=$spec.values item=value key=key} &#8211;&gt;   &nbsp; &lt;label for=&#8221;spec_value_{$value.id}&#8221;&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&#8221;radio&#8221; name=&#8221;spec_{$spec_key}&#8221; value=&#8221;{$value.id}&#8221; id=&#8221;spec_value_{$value.id}&#8221; {if $key eq 0}checked{\/if} onclick=&#8221;changePrice()&#8221; \/&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {$value.label} [{if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{\/if} {$value.format_price|abs}] &lt;\/label&gt;&lt;br \/&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!&#8211; {\/foreach} &#8211;&gt; &nbsp; &nbsp; &nbsp;   &nbsp; &nbsp;&lt;input type=&#8221;hidden&#8221; name=&#8221;spec_list&#8221; value=&#8221;{$key}&#8221; \/&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;!&#8211; {else} &#8211;&gt;   &nbsp;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;select name=&#8221;spec_{$spec_key}&#8221; onchange=&#8221;changePrice()&#8221;&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!&#8211; {foreach from=$spec.values item=value key=key} &#8211;&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option label=&#8221;{$value.label}&#8221; value=&#8221;{$value.id}&#8221;&gt;{$value.label} {if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{\/if}{if $value.price neq 0}{$value.format_price}{\/if}&lt;\/option&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!&#8211; {\/foreach} &#8211;&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;\/select&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&#8221;hidden&#8221; name=&#8221;spec_list&#8221; value=&#8221;{$key}&#8221; \/&gt;   &nbsp;&lt;!&#8211; {\/if} &#8211;&gt;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!&#8211; {\/if} &#8211;&gt; <\/p>\n<p> \u6807\u7ea2\u90e8\u5206&lt;!&#8211; {if $spec.attr_index eq 1} &#8211;&gt; \u5c31\u662f\u4e3b\u8981\u5224\u65ad\u90e8\u5206\u3002\u8fd9\u6837ecshop\u5c5e\u6027\u5217\u8868\u5c55\u793a\u5217\u8868\u65b9\u5f0f\u4e0e\u5355\u9009\u6309\u94ae\u540c\u65f6\u5b58\u5728\u4e86\u3002<br \/>\n <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u540e\u53f0\u8bbe\u5b9aecshop\u5c5e\u6027\u5217\u8868\uff0c\u5b58\u5728\u4e24\u79cd\u8bbe\u5b9a\u65b9\u5f0f\u5546\u54c1\u5c5e\u6027\u663e\u793a\u6837\u5f0f: \u5355\u9009\u6309\u94ae \u4e0e\u4e0b\u62c9\u5217\u8868\uff0c\u4f46\u662f\u6709\u65f6\u5019\u53ef\u80fd\u6211\u4eec\u9700\u8981\u8ba9ecshop\u5546\u54c1\u540c\u65f6\u652f\u6301\u4e0b\u62c9\u4e0e\u5355\u9009\u6309\u94ae\uff0c\u600e\u4e48\u529e\uff1f \u8fd9\u91cc\u597d\u6a21\u677f\u63d0\u4f9b\u7b80\u5355\u7684\u4e00\u4e2a\u65b9\u6cd5 \u5728ecshop\u8bbe\u5b9a\u5c5e\u6027\u503c\u65f6\uff0c\u5982\u4e00\u822c\u5426\u8fdb\u884c\u68c0\u7d22 \uff0c\u6211\u4eec\u90fd\u4e0d\u4f1a\u9009\u62e9\uff0c\u90a3\u4e48\u53ef\u4ee5\u8bbe\u5b9a\u8d77\u6765\uff0c\u5728\u7cfb\u7edf\u5f53\u4e2d\u4ee5\u8fd9\u4e2a\u4e3a\u53c2\u7167\u6765\u5224\u65ad\u3002 \u7528\u5230\u7684\u5b57\u6bb5attr_index \u503c\u4e3a1 1. \u627e\u5230\u7cfb\u7edflib_goods.php\u6587\u4ef6\uff0c\u51fd\u6570get_goods_properties\u3002\u589e\u52a0\u5c5e\u6027spe\u7684\u503c \u6b64\u6bb5\u6539\u6210\uff1a foreach ($res AS $row) { &nbsp; &nbsp; &nbsp; &nbsp; $row[&#8216;attr_value&#8217;] = str_replace(&#8220;\\n&#8221;, &#8216;&lt;br \/&gt;&#8217;, $row[&#8216;attr_value&#8217;]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($row[&#8216;attr_type&#8217;] == 0) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $group = (isset($groups[$row[&#8216;attr_group&#8217;]])) ? $groups[$row[&#8216;attr_group&#8217;]] : $GLOBALS[&#8216;_LANG&#8217;][&#8216;goods_attr&#8217;]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [&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-60247","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60247","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=60247"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60247\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=60247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=60247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=60247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}