首先感谢帮助...我是opencart的新手,希望有人可以帮助我...
我疯狂地试图在谷歌找到我的问题的答案......
我想在结帐/购物车中添加类别名称
<a href="<?php echo $product['href']; ?>"><?php echo $category['name']; ?></a>
我尝试在cart.pl的控制器中添加一个新变量,但是不可能,因为我在互联网上找到的答案不起作用......
BTW我在Opencart 2.2.0上工作......
这就是我在我的模板上的cart.pl中所拥有的:
<?php foreach ($products as $product) { ?>
<div class="gry_part">
<div class="width1">
<a href="<?php echo $product['href']; ?>"><?php echo $category['name']; ?></a> -
<a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
<?php if (!$product['stock']) { ?>
<span class="stock">***</span>
<?php } ?>
<div>
<?php foreach ($product['option'] as $option) { ?>
- <small><?php echo $option['name']; ?>: <?php echo $option['value']; ?></small><br />
<?php } ?>
<?php if($product['recurring']): ?>
- <small><?php echo $text_payment_profile ?>: <?php echo $product['profile_name'] ?></small>
<?php endif; ?>
</div>
<?php if ($product['reward']) { ?>
<small><?php echo $product['reward']; ?></small>
<?php } ?>
</div>
<div class="width2 quantity">
<input type="text" name="quantity[<?php echo $product['cart_id']; ?>]" value="<?php echo $product['quantity']; ?>" size="1" />
<input type="image" src="catalog/view/theme/amishop/image/update.png" alt="<?php echo $button_update; ?>" title="<?php echo $button_update; ?>" />
</div>
<div class="width3"><?php echo $product['price']; ?></div>
<div class="width4">
<button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="add_to99" onclick="cart.remove('<?php echo $product['cart_id']; ?>');">Delete</button>
</div>
</div>
<?php } ?>
这就是我尝试在控制器cart.pl
中添加的内容$categories = $this->model_catalog_product->getCategories($product_id);
if ($categories)
$categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
$this->data['category_title'] = $categories_info['name'];
对不起,如果是非常愚蠢的问题,但我是新的...
感谢所有人..
答案 0 :(得分:0)
创建OCMOD文件 - category_on_cart.ocmod.xml
复制以下代码并保存
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Category_Cart</name>
<version>1.0</version>
<code>Category_Cart</code>
<author>A2bizz</author>
<link>http://blog.a2bizz.com</link>
<file path="catalog/view/theme/*/template/checkout/cart.tpl">
<operation>
<search><![CDATA[
<td class="text-left"><?php echo $column_name; ?></td>
]]></search>
<add position="after" offset="0"><![CDATA[
<td class="text-left"><?php echo $column_category; ?></td>
]]></add>
</operation>
<operation>
<search><![CDATA[
<td class="text-left"><?php echo $product['model']; ?></td>
]]></search>
<add position="before" offset="0"><![CDATA[
<td class="text-left"><?php echo $product['category_name']; ?></td>
]]></add>
</operation>
</file>
<file path="catalog/controller/checkout/cart.php">
<operation>
<search><![CDATA[
$data['column_name'] = $this->language->get('column_name');
]]></search>
<add position="after" offset="0"><![CDATA[
$data['column_category'] = $this->language->get('column_category');
]]></add>
</operation>
<operation>
<search><![CDATA[
$this->load->model('tool/upload');
]]></search>
<add position="after" offset="0"><![CDATA[
$this->load->model('catalog/custom');
]]></add>
</operation>
<operation>
<search><![CDATA[
$product_total = 0;
]]></search>
<add position="before" offset="0"><![CDATA[
$category_name = $this->model_catalog_custom->getproductcategory($product['product_id']);
]]></add>
</operation>
<operation>
<search><![CDATA[
'name' => $product['name'],
]]></search>
<add position="after" offset="0"><![CDATA[
'category_name'=>$category_name,
]]></add>
</operation>
</file>
<file path="catalog/language/*/checkout/cart.php">
<operation>
<search><![CDATA[
$_['column_name'] = 'Product Name';
]]></search>
<add position="after" offset="0"><![CDATA[
$_['column_category'] = 'Product Category';
]]></add>
</operation>
</file>
</modification>
创建目录/ model / catalog / custom.php
在此文件中添加以下代码。
<?php
class ModelCatalogCustom extends Model {
public function getproductcategory($product_id){
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
$category = $this->getCategory($query->row['category_id']);
return $category['name'];
}
public function getCategory($category_id) {
$query = $this->db->query("SELECT DISTINCT *, (SELECT GROUP_CONCAT(cd1.name ORDER BY level SEPARATOR ' > ') FROM " . DB_PREFIX . "category_path cp LEFT JOIN " . DB_PREFIX . "category_description cd1 ON (cp.path_id = cd1.category_id AND cp.category_id != cp.path_id) WHERE cp.category_id = c.category_id AND cd1.language_id = '" . (int)$this->config->get('config_language_id') . "' GROUP BY cp.category_id) AS path, (SELECT DISTINCT keyword FROM " . DB_PREFIX . "url_alias WHERE query = 'category_id=" . (int)$category_id . "') AS keyword FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd2 ON (c.category_id = cd2.category_id) WHERE c.category_id = '" . (int)$category_id . "' AND cd2.language_id = '" . (int)$this->config->get('config_language_id') . "'");
return $query->row;
}
}
现在转到Admin dashboard -> Extensions -> Extension installer
安装category_on_Cart.ocmod.xml
文件。
之后转到Admin dashboard-> Extensions->Modifications
刷新缓存。点击右上角的刷新按钮第一个按钮。