php - 如何在 product.tpl 中为制造商描述写入 true ocmod?

标签 php opencart ocmod

我的问题:这是我的第一个 Open Cart 项目,我不知道这个 MVCL 好))所以我需要为 OpenCart 2.3.0.2 编写 ocmod 修改,以便在产品页面中添加制造商描述。早期我找到 ocmod 用于将制造商描述添加到制造商页面并为我编辑此模块此代码:

<?xml version="1.0" encoding="utf-8"?>
    <modification>
        <name>Manufacturer description</name>
        <code>default</code>
        <version>1.0</version>
        <author></author>
        <link></link>
        <!-- code admin panel -->
        <file path="admin/view/template/catalog/manufacturer_form.tpl">
        <operation>
            <search index="0"><![CDATA[<div class="form-group">]]></search>
            <add position="before"><![CDATA[
              <div class="form-group required">
                <label class="col-sm-2 control-label" for="input-description">Описание</label>
                <div class="col-sm-10">
                  <textarea name="descriptionmanufacturer" rows="5" placeholder="Описание" id="input-description" class="form-control"><?php echo isset($descriptionmanufacturer) ? $descriptionmanufacturer : ''; ?></textarea>
                 </div>
              </div>

            <script type="text/javascript">
                $('#input-description').summernote({height: 100});
            </script>
            ]]></add>
        </operation>
        </file>
        <file path="admin/controller/catalog/manufacturer.php">
        <operation>
            <search><![CDATA[$this->load->model('setting/store');]]></search>
            <add position="before"><![CDATA[
            if (isset($this->request->post['descriptionmanufacturer'])) {
                $data['descriptionmanufacturer'] = $this->request->post['descriptionmanufacturer'];
            } elseif (!empty($manufacturer_info)) {
                $data['descriptionmanufacturer'] = $manufacturer_info['descriptionm'];
            } else {
                $data['descriptionmanufacturer'] = '';
            }
                ]]></add>
        </operation>
        </file>
        <file path="admin/model/catalog/manufacturer.php">
        <operation>
            <search><![CDATA[if (isset($data['image'])) {]]></search>
            <add position="before"><![CDATA[
            if (isset($data['descriptionmanufacturer'])) {
                $this->db->query("UPDATE " . DB_PREFIX . "manufacturer SET descriptionm = '" . $this->db->escape($data['descriptionmanufacturer']) . "' WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
            }
                ]]></add>
        </operation>
        </file>
        <!-- code admin panel -->

        <!-- code view -->
        <file path="catalog/controller/product/manufacturer.php">
        <operation>
            <search><![CDATA[$data['heading_title'] = $manufacturer_info['name'];]]></search>
            <add position="before"><![CDATA[
                $data['descriptionmanufacturer'] = html_entity_decode($manufacturer_info['descriptionm'], ENT_QUOTES, 'UTF-8');

                if ($manufacturer_info['image']) {
                    $data['thumb'] = $this->model_tool_image->resize($manufacturer_info['image'], $this->config->get($this->config->get('config_theme') . '_image_category_width'), $this->config->get($this->config->get('config_theme') . '_image_category_height'));
                } else {
                    $data['thumb'] = '';
                }
                ]]></add>
        </operation>
        </file>
        <file path="catalog/view/theme/*/template/product/manufacturer_info.tpl">
        <operation>
            <search><![CDATA[<h2><?php echo $heading_title; ?></h2>]]></search>
            <add position="before"><![CDATA[
         <?php if ($descriptionmanufacturer) { ?>
            <div class="row">
            <div class="col-sm-2"><img src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ?>" title="<?php echo $heading_title; ?>" class="img-thumbnail" /></div>
            <div class="col-sm-10"><?php echo $descriptionmanufacturer; ?></div>
          </div>
          &nbsp;<br/>&nbsp;
            <?php } ?>
                ]]></add>
        </operation>
        </file>
        <!-- tab in product.tpl page -->
        <file path="catalog/controller/product/product.php">
        <operation>
            <search><![CDATA[$this->load->model('catalog/manufacturer');]]></search>
            <add position="after"><![CDATA[
                $data['descriptionmanufacturer'] = html_entity_decode($manufacturer_info['descriptionm'], ENT_QUOTES, 'UTF-8');

                if ($manufacturer_info['image']) {
                    $data['thumb'] = $this->model_tool_image->resize($manufacturer_info['image'], $this->config->get($this->config->get('config_theme') . '_image_category_width'), $this->config->get($this->config->get('config_theme') . '_image_category_height'));
                } else {
                    $data['thumb'] = '';
                }
                ]]></add>
        </operation>
        </file>

        <file path="catalog/view/theme/*/template/product/product.tpl">
        <operation>
            <search><![CDATA[<li class="active"><a href="#tab-description" data-toggle="tab"><?php echo $tab_description; ?></a></li>]]></search>
            <add position="after"><![CDATA[
            <?php if ($descriptionmanufacturer) { ?>
            <div class="row">
            <div class="col-sm-10"><?php echo $descriptionmanufacturer; ?></div>
          </div>
          &nbsp;<br/>&nbsp;
            <?php } ?>
                ]]></add>
        </operation>
        </file>
        <!-- tab in product.tpl page -->
        <!-- code voew -->
    </modification>

并在数据库中添加列:

ALTER TABLE `oc_manufacturer` ADD `descriptionm` TEXT NOT NULL AFTER `sort_order`;

我哪里做错了??这将返回此错误:

Notice: Undefined variable: manufacturer_info in C:\OpenServer\domains\apostle.loc\system\storage\modification\catalog\controller\product\product.php on line 72
Notice: Undefined variable: manufacturer_info in C:\OpenServer\domains\apostle.loc\system\storage\modification\catalog\controller\product\product.php on line 74

但我不知道我认为在 Controller 中写了什么。请帮忙!))

最佳答案

这个问题解决了!我在 Controller product.php 中错误地使用了添加代码的地方,现在它看起来是正确的:

<file path="catalog/controller/product/product.php">
<operation>
    <search><![CDATA[$data['heading_title'] = $product_info['name'];]]></search>
    <add position="after"><![CDATA[
        $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
        $data['descriptionmanufacturer'] = html_entity_decode($manufacturer_info['descriptionm'], ENT_QUOTES, 'UTF-8');
        ]]></add>
</operation>
</file>

关于php - 如何在 product.tpl 中为制造商描述写入 true ocmod?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46766878/

相关文章:

php - opencart获取最后一个订单id到成功页面

javascript - .js 文件修改不适用于 ocmod opencart

php - Opencart 2.3 注意:未定义属性:Proxy::function_name

php - 单点登录或通过 PHP 登录

php - 不存在查询的 MySQL 性能不佳

php - 如何从字符串中提取数字部分

php - 从mysql数据库中恢复保存为 "???????"的原始数据

php - opencart seo 友好 url 仅适用于某些页面

Opencart 3.x 新主题未显示在管理面板中?

php - 在 OpenCart 中安装 OCMOD 文件