必要なコードはすべて、OpenCartファイルに既に存在しています。 たとえば、catalog/model/catalog/category.php
に移動してgetCategories
というコピーを作成し、名前を変更して編集します。
私はあなたがvQmodを使用しない場合は、手動でファイルをここにocmodまたは編集するためにそれを変換することができ、ご希望のタスクを実行するvQmodスクリプトを作成しましたが、結果のスクリーンショットです:
とXMLファイル:
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Stores List With Their Categories</id>
<version>2.x</version>
<vqmver>2.6.0</vqmver>
<author>[email protected]</author>
<file name="catalog/controller/module/store.php">
<operation error="skip">
<search position="replace" index="1"><![CDATA[$data['stores'][] = array(]]></search>
<add><![CDATA[
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$store_categories = array();
$categories = $this->model_catalog_category->getStoreCategories(0);
foreach ($categories as $category) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getStoreCategories(0, $category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$store_categories[] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
$data['stores'][] = array(
'categories' => $store_categories,
]]></add>
</operation>
<operation error="skip">
<search position="replace" index="2"><![CDATA[$data['stores'][] = array(]]></search>
<add><![CDATA[
$store_categories = array();
$categories = $this->model_catalog_category->getStoreCategories($result['store_id']);
foreach ($categories as $category) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getStoreCategories($result['store_id'], $category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$store_categories[] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
$data['stores'][] = array(
'categories' => $store_categories,
]]></add>
</operation>
</file>
<file name="catalog/view/theme/*/template/module/store.tpl">
<operation error="skip">
<search position="after"><![CDATA[<?php echo $store['name']; ?>]]></search>
<add><![CDATA[
<?php if ($store['categories']) { ?>
<ul>
<?php foreach ($store['categories'] as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<?php foreach (array_chunk($category['children'], ceil(count($category['children'])/$category['column'])) as $children) { ?>
<ul>
<?php foreach ($children as $child) { ?>
<li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
]]></add>
</operation>
</file>
<file name="catalog/model/catalog/category.php">
<operation error="skip">
<search position="before"><![CDATA[public function getCategories($parent_id = 0) {]]></search>
<add><![CDATA[
public function getStoreCategories($store_id, $parent_id = 0) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.parent_id = '" . (int)$parent_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$store_id . "' AND c.status = '1' ORDER BY c.sort_order, LCASE(cd.name)");
return $query->rows;
}
]]></add>
</operation>
</file>
</modification>
編集: ここではデフォルトのテーマをopencart 2.0.3.1でテストocmodのバージョンは、あります。
アップロードするOCMODファイルのファイル拡張子は、 .ocmod.zipまたは.ocmod.xmlのいずれかである必要があります。これは、店舗ユーザーの管理者にアップロードされたOCMODファイルがないことを避けるためです。
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<name>Stores List With Their Categories</name>
<version>2.x</version>
<author>[email protected]</author>
<code>Stores List With Their Categories</code>
<file path="catalog/controller/module/store.php">
<operation>
<search index="0"><![CDATA[$data['stores'][] = array(]]></search>
<add position="replace"><![CDATA[
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$store_categories = array();
$categories = $this->model_catalog_category->getStoreCategories(0);
foreach ($categories as $category) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getStoreCategories(0, $category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$store_categories[] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
$data['stores'][] = array(
'categories' => $store_categories,
]]></add>
</operation>
<operation>
<search index="1"><![CDATA[$data['stores'][] = array(]]></search>
<add position="replace"><![CDATA[
$store_categories = array();
$categories = $this->model_catalog_category->getStoreCategories($result['store_id']);
foreach ($categories as $category) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getStoreCategories($result['store_id'], $category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$store_categories[] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
$data['stores'][] = array(
'categories' => $store_categories,
]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/module/store.tpl">
<operation>
<search><![CDATA[<?php echo $store['name']; ?>]]></search>
<add position="after"><![CDATA[
<?php if ($store['categories']) { ?>
<ul>
<?php foreach ($store['categories'] as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<?php foreach (array_chunk($category['children'], ceil(count($category['children'])/$category['column'])) as $children) { ?>
<ul>
<?php foreach ($children as $child) { ?>
<li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
]]></add>
</operation>
</file>
<file path="catalog/model/catalog/category.php">
<operation>
<search><![CDATA[public function getCategories($parent_id = 0) {]]></search>
<add position="before"><![CDATA[
public function getStoreCategories($store_id, $parent_id = 0) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.parent_id = '" . (int)$parent_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$store_id . "' AND c.status = '1' ORDER BY c.sort_order, LCASE(cd.name)");
return $query->rows;
}
]]></add>
</operation>
</file>
</modification>
vqmodとocmodの違いについては、この良い記事を参照してください。 https://forum.opencart.com/viewtopic.php?f=24&t=131995
うわー、それは大きな助けです!あなたは私のヒーローです!しかし、私はopencartで経験したことはありません....だから、コードの実装を理解する時間がかかります...私もocmodに変換する必要があります。私はocmodファイルについても良い文書を見つけることができません。私が見つけた唯一の事は[link](https://github.com/opencart/opencart/wiki/Modification-System)です。例えばerror = "skip"とはどういう意味ですか?(ocmodではこの属性が見えませんでした)?またはインデックス属性? ocmodの使い方についてもっと知ることができますか?しかし、ありがとうございます。 –
こんにちは、あなたは歓迎です、なぜあなたはvQmodを使いませんか?すぐに私の投稿にocmod版を追加します。 – DigitCart
私の雇用者には、ocmodの使用を推奨する別の開発者がいます...私はこれについて何も言及していません...そしてもう一度感謝します!良い週末を! –