{"id":199372,"date":"2025-05-03T12:35:17","date_gmt":"2025-05-03T04:35:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199372\/"},"modified":"2025-05-03T12:35:17","modified_gmt":"2025-05-03T04:35:17","slug":"%e5%9c%a8ecshop%e5%95%86%e5%93%81%e9%a1%b5%e8%af%a6%e6%83%85%e9%a1%b5%e6%b7%bb%e5%8a%a0%e5%90%8c%e7%b1%bb%e9%9a%8f%e6%9c%ba%e5%95%86%e5%93%81","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199372\/","title":{"rendered":"\u5728ecshop\u5546\u54c1\u9875\u8be6\u60c5\u9875\u6dfb\u52a0\u540c\u7c7b\u968f\u673a\u5546\u54c1"},"content":{"rendered":"<p> \u5728ecshop\u5546\u54c1\u9875\u8be6\u60c5\u9875\u6dfb\u52a0\u540c\u7c7b\u968f\u673a\u5546\u54c1\uff0c\u80fd\u8d77\u5230\u66f4\u597d\u7684\u5c55\u793a\u6548\u679c\uff0c\u7f8e\u89c2\u7684\u5ba2\u6237\u4f53\u9a8c\uff0c\u52a0\u8ba9\u7cfb\u7edf\u66f4\u65b9\u4fbf\u641c\u7d22\u5f15\u64ce\u6293\u53d6\u3002\u597d\u6a21\u677f\u63d0\u4f9b\u8be5\u3002<\/p>\n<p> 1\uff0cecshop\u6839\u76ee\u5f55\u4e0b\u627e\u5230goods.php\u6587\u4ef6<\/p>\n<p> \u627e\u5230ecshop\u4ee3\u7801&nbsp; $smarty-&gt;assign(&#8216;properties&#8217;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $properties[&#8216;pro&#8217;]);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ \u5546\u54c1\u5c5e\u6027<\/p>\n<p> \u5728\u4e0a\u9762\u52a0\u4ee3\u7801 $smarty-&gt;assign(&#8216;category_related_random_goods&#8217;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; category_related_random_goods($goods[&#8216;cat_id&#8217;])); \/\/ \u540c\u5206\u7c7b\u968f\u673a\u5546\u54c1<\/p>\n<p> &nbsp; \u518d\u5728ecshop\u6700\u5e95\u90e8\u6dfb\u52a0\u4e0a \u968f\u673a\u540c\u7c7b\u5546\u54c1\u7684\u51fd\u6570\uff0c \u4ee5\u4e0b\u4ee3\u7801 &nbsp; <\/p>\n<pre>\r\n\/*\u540c\u5206\u7c7b\u4e0b\u968f\u673a\u63a8\u8350\u5546\u54c1*\/\r\nfunction category_related_random_goods($category_id)\r\n{\r\n    $where = \"g.is_on_sale = 1 AND g.is_alone_sale = 1 AND \".\r\n            \"g.is_delete = 0 AND g.cat_id=$category_id \";\r\n    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .\r\n                \"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, \" .\r\n                'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .\r\n            'FROM ' . $GLOBALS['ecs']-&gt;table('goods') . ' AS g ' .\r\n            'LEFT JOIN ' . $GLOBALS['ecs']-&gt;table('member_price') . ' AS mp ' .\r\n                \"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' \" .\r\n            \"WHERE $where ORDER BY rand() limit 12\";\r\n    $res = $GLOBALS['db']-&gt;query($sql);\r\n    $arr = array();<span style=\"color:#ffffff\">\/\/www.ldhost.cn<\/span>\r\n    while ($row = $GLOBALS['db']-&gt;fetchRow($res))\r\n    {\r\n        $arr[$row['goods_id']]['goods_id']     = $row['goods_id'];\r\n        $arr[$row['goods_id']]['goods_name']   = $row['goods_name'];\r\n        $arr[$row['goods_id']]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] &gt; 0 ?\r\n            sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];\r\n        $arr[$row['goods_id']]['goods_thumb']  = get_image_path($row['goods_id'], $row['goods_thumb'], true);\r\n        $arr[$row['goods_id']]['goods_img']    = get_image_path($row['goods_id'], $row['goods_img']);\r\n        $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);\r\n        $arr[$row['goods_id']]['shop_price']   = price_format($row['shop_price']);\r\n        $arr[$row['goods_id']]['url']          = build_uri('goods', array('gid'=&gt;$row['goods_id']), $row['goods_name']);\r\n        if ($row['promote_price'] &gt; 0)\r\n        {\r\n            $arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);\r\n            $arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']);\r\n        }\r\n        else\r\n        {\r\n            $arr[$row['goods_id']]['promote_price'] = 0;\r\n        }\r\n    }\r\n    return $arr;\r\n}<\/pre>\n<p> &nbsp; <\/p>\n<p> 2\uff0c\u65b0\u5efa\u6587\u4ef6 category_related_random_goods.lbi<br \/> \u4ee3\u7801\u5982\u4e0b<\/p>\n<p> &nbsp; <\/p>\n<pre>\r\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\"&gt;\r\n&lt;!-- {if $category_related_random_goods} --&gt;\r\n &lt;div class=\"box\"&gt;\r\n        &lt;h3&gt;Related Products&lt;\/h3&gt;\r\n        &lt;div&gt;\r\n        &lt;ul&gt;\r\n        &lt;!--{foreach from=$category_related_random_goods item=category_related_random_goods_data}--&gt;           \r\n        &lt;li class=\"li1\" style=\"float:left; margin-bottom:20px;\"&gt;&lt;a href=\"{$category_related_random_goods_data.url}\"&gt;&lt;img src=\"{$category_related_random_goods_data.goods_thumb}\" alt=\"{$category_related_random_goods_data.goods_name}\"\/&gt;&lt;\/a&gt;&lt;\/li&gt;\r\n        &lt;li class=\"li2\" style=\"float:left; margin-bottom:20px;\"&gt;&lt;a href=\"{$category_related_random_goods_data.url}\" title=\"{$category_related_random_goods_data.goods_name}\"&gt;{$category_related_random_goods_data.short_name}&lt;\/a&gt;&lt;br \/&gt;\r\n        &lt;!-- {if $category_related_random_goods_data.promote_price neq 0} --&gt;\r\n        {$lang.promote_price}&lt;font class=\"f1\"&gt;{$category_related_random_goods_data.formated_promote_price}&lt;\/font&gt;\r\n        &lt;!-- {else} --&gt;\r\n        {$lang.shop_price}&lt;font class=\"f1\"&gt;{$category_related_random_goods_data.shop_price}&lt;\/font&gt;\r\n        &lt;!-- {\/if} --&gt;&lt;\/li&gt;\r\n        &lt;!--{\/foreach}--&gt;\r\n        &lt;\/ul&gt;\r\n        &lt;\/div&gt;\r\n &lt;\/div&gt;\r\n&lt;div class=\"blank5\"&gt;&lt;\/div&gt;\r\n&lt;!-- {\/if} --&gt;<\/pre>\n<p> \u6837\u5f0f\u53ef\u4ee5\u81ea\u5df1\u5b9a\u4e49<br \/> \u628acategory_related_random_goods.lbi\u6587\u4ef6\u590d\u5236\u5230 \/themes\/\u4f60\u4f7f\u7528\u7684\u6a21\u677f\/library\/&nbsp;&nbsp; \u6587\u4ef6\u5939\u91cc<\/p>\n<p> &nbsp;<br \/>\n<br \/> 3\uff0cecshop\u627e\u5230&nbsp; \/themes\/\u4f60\u4f7f\u7528\u7684\u6a21\u677f\/goods.dwt&nbsp; \u6587\u4ef6 \u52a0\u4e0a<br \/>\n<br \/> &lt;!&#8211; #BeginLibraryItem &#8220;\/library\/category_related_random_goods.lbi&#8221; &#8211;&gt;&lt;!&#8211; #EndLibraryItem &#8211;&gt; <\/p>\n<p> \u52a0\u5728 &lt;!&#8211; #BeginLibraryItem &#8220;\/library\/goods_tags.lbi&#8221; &#8211;&gt;&lt;!&#8211; #EndLibraryItem &#8211;&gt; &nbsp; \u5176\u4ed6ecshop\u6a21\u5757\u662f\u540c\u7406\u7684 &nbsp; PS:&nbsp;googs.php&nbsp;\u91cc ORDER&nbsp;BY&nbsp;rand()&nbsp;limit&nbsp;12&nbsp;&nbsp; \u8fd9\u4e2a\u4ee3\u7801&nbsp;12&nbsp;\u5c31\u662f\u663e\u793a\u4e2a\u6570\u7684<br \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728ecshop\u5546\u54c1\u9875\u8be6\u60c5\u9875\u6dfb\u52a0\u540c&#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-199372","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199372","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=199372"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199372\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}