{"id":60730,"date":"2025-04-26T11:39:49","date_gmt":"2025-04-26T03:39:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/60730\/"},"modified":"2025-04-26T11:39:49","modified_gmt":"2025-04-26T03:39:49","slug":"%e8%a7%a3%e5%86%b3zencart%e5%90%8e%e5%8f%b0%e7%9b%ae%e5%bd%95%e4%ba%a7%e5%93%81%e9%bb%84%e8%89%b2icon_yellow_on-gif%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/60730\/","title":{"rendered":"\u89e3\u51b3zencart\u540e\u53f0\u76ee\u5f55\u4ea7\u54c1\u9ec4\u8272icon_yellow_on.gif\u65b9\u6cd5"},"content":{"rendered":"<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> \u89e3\u51b3\u65b9\u6cd5\uff0c\u5bfc\u5165\u65f6\u5019\u53d1\u73b0&nbsp;<span style=\"margin: 0px;padding: 0px;line-height: 1.5\"><strong>\u66f4\u65b0\u6210\u529f! &#8211; \u578b\u53f7:<\/strong>&nbsp;as NO.1209 \u5c31\u662f\u91cd\u590dmodel<\/span><\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> \u6587\u4ef6\u4f4d\u7f6e\uff1amanager\\includes\\modules\\category_product_listing.php<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> \u6587\u4ef6\u5185\u5bb9\uff1a<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> \u3000\u3000if (zen_get_products_to_categories($categories-&gt;fields[&#8216;categories_id&#8217;], true, &#8216;products_active&#8217;) == &#8216;true&#8217;) {<br \/> \u3000\u3000echo &#8216;&amp;nbsp;&amp;nbsp;&#8217; . zen_image(DIR_WS_IMAGES . &#8216;icon_yellow_on.gif&#8217;, IMAGE_ICON_LINKED);<br \/> \u3000\u3000}<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> \u51fd\u6570\u4f4d\u7f6e\uff1a \u540e\u53f0\\includes\\functions\\general.php<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> \u51fd\u6570\u5185\u5bb9\uff1a<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> function zen_get_products_to_categories($category_id, $include_inactive = false, $counts_what = &#8216;products&#8217;) {<br \/> global $db;<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> $products_count = 0;<br \/> if ($include_inactive == true) {<br \/> switch ($counts_what) {<br \/> case (&#8216;products&#8217;):<br \/> $cat_products_query = &#8220;select count(*) as total<br \/> from &#8221; . TABLE_PRODUCTS . &#8221; p, &#8221; . TABLE_PRODUCTS_TO_CATEGORIES . &#8221; p2c<br \/> where p.products_id = p2c.products_id<br \/> and p2c.categories_id = &#8216;&#8221; . (int)$category_id . &#8220;&#8216;&#8221;;<br \/> break;<br \/> case (&#8216;products_active&#8217;):<br \/> <span style=\"margin: 0px;padding: 0px;line-height: 1.5\">$cat_products_query = &#8220;select p.products_id<\/span><br \/> <span style=\"margin: 0px;padding: 0px;line-height: 1.5\">from &#8221; . TABLE_PRODUCTS . &#8221; p, &#8221; . TABLE_PRODUCTS_TO_CATEGORIES . &#8221; p2c<\/span><br \/> <span style=\"margin: 0px;padding: 0px;line-height: 1.5\">where p.products_id = p2c.products_id<\/span><br \/> <span style=\"margin: 0px;padding: 0px;line-height: 1.5\">and p2c.categories_id = &#8216;&#8221; . (int)$category_id . &#8220;&#8216;&#8221;;<\/span><br \/> break;<br \/> }<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> } else {<br \/> switch ($counts_what) {<br \/> case (&#8216;products&#8217;):<br \/> $cat_products_query = &#8220;select count(*) as total<br \/> from &#8221; . TABLE_PRODUCTS . &#8221; p, &#8221; . TABLE_PRODUCTS_TO_CATEGORIES . &#8221; p2c<br \/> where p.products_id = p2c.products_id<br \/> and p.products_status = 1<br \/> and p2c.categories_id = &#8216;&#8221; . (int)$category_id . &#8220;&#8216;&#8221;;<br \/> break;<br \/> case (&#8216;products_active&#8217;):<br \/> $cat_products_query = &#8220;select p.products_id<br \/> from &#8221; . TABLE_PRODUCTS . &#8221; p, &#8221; . TABLE_PRODUCTS_TO_CATEGORIES . &#8221; p2c<br \/> where p.products_id = p2c.products_id<br \/> and p.products_status = 1<br \/> and p2c.categories_id = &#8216;&#8221; . (int)$category_id . &#8220;&#8216;&#8221;;<br \/> break;<br \/> }<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> }<br \/> $cat_products = $db-&gt;Execute($cat_products_query);<br \/> switch ($counts_what) {<br \/> case (&#8216;products&#8217;):<br \/> $cat_products_count += $cat_products-&gt;fields[&#8216;total&#8217;];<br \/> break;<br \/> case (&#8216;products_active&#8217;):<br \/> while (!$cat_products-&gt;EOF) {<br \/> if (zen_get_product_is_linked($cat_products-&gt;fields[&#8216;products_id&#8217;]) == &#8216;true&#8217;) {<br \/> return $products_linked = &#8216;true&#8217;;<br \/> }<br \/> $cat_products-&gt;MoveNext();<br \/> }<br \/> break;<br \/> }<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> $cat_child_categories_query = &#8220;select categories_id<br \/> from &#8221; . TABLE_CATEGORIES . &#8220;<br \/> where parent_id = &#8216;&#8221; . (int)$category_id . &#8220;&#8216;&#8221;;<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> $cat_child_categories = $db-&gt;Execute($cat_child_categories_query);<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> if ($cat_child_categories-&gt;RecordCount() &gt; 0) {<br \/> while (!$cat_child_categories-&gt;EOF) {<br \/> switch ($counts_what) {<br \/> case (&#8216;products&#8217;):<br \/> $cat_products_count += zen_get_products_to_categories($cat_child_categories-&gt;fields[&#8216;categories_id&#8217;], $include_inactive);<br \/> break;<br \/> case (&#8216;products_active&#8217;):<br \/> if (zen_get_products_to_categories($cat_child_categories-&gt;fields[&#8216;categories_id&#8217;], true, &#8216;products_active&#8217;) == &#8216;true&#8217;) {<br \/> return $products_linked = &#8216;true&#8217;;<br \/> }<br \/> break;<br \/> }<br \/> $cat_child_categories-&gt;MoveNext();<br \/> }<br \/> }<\/p>\n<p style=\"margin: 10px auto;padding: 0px;line-height: 19.5px;font-size: 13px\"> switch ($counts_what) {<br \/> case (&#8216;products&#8217;):<br \/> return $cat_products_count;<br \/> break;<br \/> case (&#8216;products_active&#8217;):<br \/> return $products_linked;<br \/> break;<br \/> }<br \/> }<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u51b3\u65b9\u6cd5\uff0c\u5bfc\u5165\u65f6\u5019\u53d1\u73b0&nbsp;\u66f4\u65b0\u6210\u529f! &#8211; \u578b\u53f7:&nbsp;as NO.1209 \u5c31\u662f\u91cd\u590dmodel \u6587\u4ef6\u4f4d\u7f6e\uff1amanager\\includes\\modules\\category_product_listing.php \u6587\u4ef6\u5185\u5bb9\uff1a \u3000\u3000if (zen_get_products_to_categories($categories-&gt;fields[&#8216;categories_id&#8217;], true, &#8216;products_active&#8217;) == &#8216;true&#8217;) { \u3000\u3000echo &#8216;&amp;nbsp;&amp;nbsp;&#8217; . zen_image(DIR_WS_IMAGES . &#8216;icon_yellow_on.gif&#8217;, IMAGE_ICON_LINKED); \u3000\u3000} \u51fd\u6570\u4f4d\u7f6e\uff1a \u540e\u53f0\\includes\\functions\\general.php \u51fd\u6570\u5185\u5bb9\uff1a \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ function zen_get_products_to_categories($category_id, $include_inactive = false, $counts_what = &#8216;products&#8217;) { global $db; $products_count = 0; if ($include_inactive == true) { switch ($counts_what) { case (&#8216;products&#8217;): $cat_products_query = &#8220;select count(*) as [&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-60730","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60730","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=60730"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60730\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=60730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=60730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=60730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}