Php 在Opencart的每个页面上显示所需的产品选项
我们可以在opencart中创建自定义选项,并根据需要将这些选项与产品链接。我想在每个页面上显示所需的产品选项,即类别、搜索结果,而不是仅在产品详细信息页面上显示 通过编辑以下两个文件,可以在类别中显示所需选项: 文件:Php 在Opencart的每个页面上显示所需的产品选项,php,opencart,opencart-3,Php,Opencart,Opencart 3,我们可以在opencart中创建自定义选项,并根据需要将这些选项与产品链接。我想在每个页面上显示所需的产品选项,即类别、搜索结果,而不是仅在产品详细信息页面上显示 通过编辑以下两个文件,可以在类别中显示所需选项: 文件: catalog\controller\product\category.php $data['products'][] = array( $options = array(); foreach ($this->model_catalog_product->ge
catalog\controller\product\category.php
$data['products'][] = array(
$options = array();
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
if($option['required']){
$product_option_value_data = array();
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $result['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
} else {
$price = false;
}
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$options[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
}
$data['products'][] = array(
'options' => $options,
catalog\view\theme\default\template\product\category.twig
<div class="button-group">
{% if product.options %}
<hr>
<h3>{{ text_option }}</h3>
{% for option in product.options %}
{% if option.type == 'select' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
<option value="">{{ text_select }}</option>
{% for option_value in option.product_option_value %}
<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </option>
{% endfor %}
</select>
</div>
{% endif %}
{% if option.type == 'radio' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="radio">
<label>
<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'checkbox' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="checkbox">
<label>
<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'text' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" />
</div>
{% endif %}
{% if option.type == 'textarea' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<textarea name="option[{{ option.product_option_id }}]" rows="5" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control">{{ option.value }}</textarea>
</div>
{% endif %}
{% if option.type == 'file' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>
<input type="hidden" name="option[{{ option.product_option_id }}]" value="" id="input-option{{ option.product_option_id }}" />
</div>
{% endif %}
{% if option.type == 'date' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group date">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'datetime' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group datetime">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'time' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group time">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% endfor %}
{% endif %}
查找:
catalog\controller\product\category.php
$data['products'][] = array(
$options = array();
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
if($option['required']){
$product_option_value_data = array();
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $result['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
} else {
$price = false;
}
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$options[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
}
$data['products'][] = array(
'options' => $options,
catalog\view\theme\default\template\product\category.twig
<div class="button-group">
{% if product.options %}
<hr>
<h3>{{ text_option }}</h3>
{% for option in product.options %}
{% if option.type == 'select' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
<option value="">{{ text_select }}</option>
{% for option_value in option.product_option_value %}
<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </option>
{% endfor %}
</select>
</div>
{% endif %}
{% if option.type == 'radio' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="radio">
<label>
<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'checkbox' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="checkbox">
<label>
<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'text' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" />
</div>
{% endif %}
{% if option.type == 'textarea' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<textarea name="option[{{ option.product_option_id }}]" rows="5" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control">{{ option.value }}</textarea>
</div>
{% endif %}
{% if option.type == 'file' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>
<input type="hidden" name="option[{{ option.product_option_id }}]" value="" id="input-option{{ option.product_option_id }}" />
</div>
{% endif %}
{% if option.type == 'date' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group date">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'datetime' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group datetime">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'time' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group time">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% endfor %}
{% endif %}
替换为:
catalog\controller\product\category.php
$data['products'][] = array(
$options = array();
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
if($option['required']){
$product_option_value_data = array();
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $result['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
} else {
$price = false;
}
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$options[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
}
$data['products'][] = array(
'options' => $options,
catalog\view\theme\default\template\product\category.twig
<div class="button-group">
{% if product.options %}
<hr>
<h3>{{ text_option }}</h3>
{% for option in product.options %}
{% if option.type == 'select' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
<option value="">{{ text_select }}</option>
{% for option_value in option.product_option_value %}
<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </option>
{% endfor %}
</select>
</div>
{% endif %}
{% if option.type == 'radio' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="radio">
<label>
<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'checkbox' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="checkbox">
<label>
<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'text' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" />
</div>
{% endif %}
{% if option.type == 'textarea' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<textarea name="option[{{ option.product_option_id }}]" rows="5" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control">{{ option.value }}</textarea>
</div>
{% endif %}
{% if option.type == 'file' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>
<input type="hidden" name="option[{{ option.product_option_id }}]" value="" id="input-option{{ option.product_option_id }}" />
</div>
{% endif %}
{% if option.type == 'date' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group date">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'datetime' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group datetime">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'time' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group time">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% endfor %}
{% endif %}
文件:
catalog\controller\product\category.php
$data['products'][] = array(
$options = array();
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
if($option['required']){
$product_option_value_data = array();
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $result['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
} else {
$price = false;
}
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$options[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
}
$data['products'][] = array(
'options' => $options,
catalog\view\theme\default\template\product\category.twig
<div class="button-group">
{% if product.options %}
<hr>
<h3>{{ text_option }}</h3>
{% for option in product.options %}
{% if option.type == 'select' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
<option value="">{{ text_select }}</option>
{% for option_value in option.product_option_value %}
<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </option>
{% endfor %}
</select>
</div>
{% endif %}
{% if option.type == 'radio' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="radio">
<label>
<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'checkbox' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="checkbox">
<label>
<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'text' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" />
</div>
{% endif %}
{% if option.type == 'textarea' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<textarea name="option[{{ option.product_option_id }}]" rows="5" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control">{{ option.value }}</textarea>
</div>
{% endif %}
{% if option.type == 'file' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>
<input type="hidden" name="option[{{ option.product_option_id }}]" value="" id="input-option{{ option.product_option_id }}" />
</div>
{% endif %}
{% if option.type == 'date' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group date">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'datetime' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group datetime">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'time' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group time">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% endfor %}
{% endif %}
在for循环的内部某处,或查找:
catalog\controller\product\category.php
$data['products'][] = array(
$options = array();
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
if($option['required']){
$product_option_value_data = array();
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $result['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
} else {
$price = false;
}
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$options[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
}
$data['products'][] = array(
'options' => $options,
catalog\view\theme\default\template\product\category.twig
<div class="button-group">
{% if product.options %}
<hr>
<h3>{{ text_option }}</h3>
{% for option in product.options %}
{% if option.type == 'select' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
<option value="">{{ text_select }}</option>
{% for option_value in option.product_option_value %}
<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </option>
{% endfor %}
</select>
</div>
{% endif %}
{% if option.type == 'radio' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="radio">
<label>
<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'checkbox' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="checkbox">
<label>
<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'text' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" />
</div>
{% endif %}
{% if option.type == 'textarea' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<textarea name="option[{{ option.product_option_id }}]" rows="5" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control">{{ option.value }}</textarea>
</div>
{% endif %}
{% if option.type == 'file' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>
<input type="hidden" name="option[{{ option.product_option_id }}]" value="" id="input-option{{ option.product_option_id }}" />
</div>
{% endif %}
{% if option.type == 'date' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group date">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'datetime' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group datetime">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'time' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group time">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% endfor %}
{% endif %}
在其前面添加:
catalog\controller\product\category.php
$data['products'][] = array(
$options = array();
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
if($option['required']){
$product_option_value_data = array();
foreach ($option['product_option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $result['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
} else {
$price = false;
}
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$options[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
}
$data['products'][] = array(
'options' => $options,
catalog\view\theme\default\template\product\category.twig
<div class="button-group">
{% if product.options %}
<hr>
<h3>{{ text_option }}</h3>
{% for option in product.options %}
{% if option.type == 'select' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
<option value="">{{ text_select }}</option>
{% for option_value in option.product_option_value %}
<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </option>
{% endfor %}
</select>
</div>
{% endif %}
{% if option.type == 'radio' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="radio">
<label>
<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'checkbox' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
<div class="checkbox">
<label>
<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" />
{% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
{{ option_value.name }}
{% if option_value.price %}
({{ option_value.price_prefix }}{{ option_value.price }})
{% endif %} </label>
</div>
{% endfor %} </div>
</div>
{% endif %}
{% if option.type == 'text' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" />
</div>
{% endif %}
{% if option.type == 'textarea' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<textarea name="option[{{ option.product_option_id }}]" rows="5" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control">{{ option.value }}</textarea>
</div>
{% endif %}
{% if option.type == 'file' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label">{{ option.name }}</label>
<button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>
<input type="hidden" name="option[{{ option.product_option_id }}]" value="" id="input-option{{ option.product_option_id }}" />
</div>
{% endif %}
{% if option.type == 'date' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group date">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'datetime' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group datetime">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% if option.type == 'time' %}
<div class="form-group{% if option.required %} required {% endif %}">
<label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
<div class="input-group time">
<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
</div>
{% endif %}
{% endfor %}
{% endif %}
{%if product.options%}
{{text_option}}
{product.options%中的选项为%s}
{%if option.type='选择“%”
{{option.name}
{{text_select}}
{option.product_option_value%}
{{option_value.name}
{%if选项_value.price%}
({{option_value.price_prefix}{{option_value.price}})
{%endif%}
{%endfor%}
{%endif%}
{%if option.type=='radio%}
{{option.name}
{option.product_option_value%}
{%if选项_value.image%}{%endif%}
{{option_value.name}
{%if选项_value.price%}
({{option_value.price_prefix}{{option_value.price}})
{%endif%}
{%endfor%}
{%endif%}
{%if option.type='复选框“%”
{{option.name}
{option.product_option_value%}
{%if选项_value.image%}{%endif%}
{{option_value.name}
{%if选项_value.price%}
({{option_value.price_prefix}{{option_value.price}})
{%endif%}
{%endfor%}
{%endif%}
{%if option.type=='文本'%}
{{option.name}
{%endif%}
{%if option.type='textarea%}
{{option.name}
{{option.value}}
{%endif%}
{%if option.type=='文件'%}
{{option.name}
{{按钮上传}
{%endif%}
{%if option.type=='日期'%}
{{option.name}
{%endif%}
{%if option.type=='datetime%}
{{option.name}
{%endif%}
{%if option.type=='time%}
{{option.name}
{%endif%}
{%endfor%}
{%endif%}
然后清除您的
ocmod
、vqmod
和twig
缓存并检查它。这对我来说很有效,但通过更改选项,产品的速率也应该更新。一些ajax机制需要在选项的OnChange事件中实现,这是为了显示选项,在选择任何选项后更新产品价格,以及为了添加到购物车按钮,您需要额外的代码。