3

我的问题:这是我的第一个 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

但我不知道我认为控制器中写了什么。请帮忙!))

4

1 回答 1

0

这个问题解决了!我错误地在控制器 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>
于 2017-10-16T11:33:31.123 回答