我是php和opencart的新手。但是打算开设我的网店。 我正在创建一个选项,在opencart的结账页面中选择一个交货时间段。 如下图所示:
所以,我开始编写一个vqmod,但仍坚持如何将值存储在数据库中: 我的xml看起来像这样:
<modification>
<id>Salutation Field Modification</id>
<version>1</version>
<vqmver>1.0.8</vqmver>
<author>maca</author>
<file name="catalog/view/theme/bigshop/template/checkout/shipping_method.tpl">
<operation>
<search position="before"><![CDATA[
<p><?php echo $text_shipping_method; ?></p>
]]></search>
<add><![CDATA[
<p><?php echo $text_shipping_timeslot; ?></p>
<table class="radio">
<tr>
<td colspan="3"><b><?php echo "Delivery time slot"; ?></b></td>
</tr>
<tr class="highlight">
<td>
<input type="radio" name="shipping_timeslot" value="><?php echo $ship_slot_one; ?></" id="morning?>" checked="checked"/><?php echo $ship_slot_one; ?></br>
<input type="radio" name="shipping_timeslot" value="><?php echo $ship_slot_two; ?></" id="afternoon?>"/><?php echo $ship_slot_two; ?></br>
<input type="radio" name="shipping_timeslot" value="><?php echo $ship_slot_three; ?></" id="evening?>"/><?php echo $ship_slot_three; ?></br>
<input type="radio" name="shipping_timeslot" value="><?php echo $ship_slot_four; ?></" id="night?>"/><?php echo $ship_slot_four; ?></br>
</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
</table>
]]></add>
</operation>
</file>
<file name="catalog/language/english/checkout/checkout.php">
<operation>
<search position="before"><![CDATA[
$_['text_shipping_method'] = 'Please select the preferred shipping method to use on this order.';
]]></search>
<add><![CDATA[
$_['text_shipping_timeslot'] = 'Please select the preferred shipping time slot.';
$_['ship_slot_one'] = 'Morning';
$_['ship_slot_two'] = 'Afternoon';
$_['ship_slot_three'] = 'Evening';
$_['ship_slot_four'] = 'Night';
]]></add>
</operation>
</file>
<file name="catalog/controller/checkout/shipping_method.php">
<operation>
<search position="before"><![CDATA[
$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
]]></search>
<add><![CDATA[
$this->data['text_shipping_timeslot'] = $this->language->get('text_shipping_timeslot');
$this->data['ship_slot_one'] = $this->language->get('ship_slot_one');
$this->data['ship_slot_two'] = $this->language->get('ship_slot_two');
$this->data['ship_slot_three'] = $this->language->get('ship_slot_three');
$this->data['ship_slot_four'] = $this->language->get('ship_slot_four');
]]></add>
</operation>
</file>
</modification>
请指导我。
答案 0 :(得分:1)
正如 Floris 所提到的那样 - 输入的值部分中有>
个符号,这是不正确的。此外,最好将输入的标签放入真正的HTML 标签,以便在点击该标签时检查复选框/收音机(点击小复选框/收音机不是很舒服直接地)。
现在您的保存问题:我建议在表order
中创建一个名为shipping_time_slot
且类型为enum('opt1', 'opt2', 'etc.')
的新数据库列。在这里您将存储您选择的运送时段。
现在对于控制器,您必须修改(通过vQmod)catalog/controller/checkout/shipping_method.php
(此外,您应该对访客结帐执行相同的修改 - 应用不同的文件)并接收shipping_timeslot
值从POST中将其与所有其他送货信息一起保存到会话中。
最后(但不是真的)您必须修改模型catalog/model/checkout/order.php
和方法addOrder()
以将shipping_timeslot
值保存到数据库中。
这应该只是存储到数据库中。
但是您应该记住,您还应该扩展后端(管理)以便能够从数据库加载shipping_timeslot
值并在订单详细信息中显示它们 - 这意味着至少修改这些文件:
admin/controller/sale/order.php
admin/model/sale/order.php
(可能不需要)admin/language/<YOUR_LANG>/sale/order.php
- 为shipping_timeslot admin/view/template/sale/order_info.tpl
和admin/view/template/sale/order_form.tpl
答案 1 :(得分:0)
Here is full solution....
Open file..
/*** TIME SLOT OPENCART CODING ***/
C:\wamp\www\OC\catalog\controller\checkout\shipping_method.php
1)
Find :-
$this->session->data['comment'] = strip_tags($this->request->post['comment']);
After that copy and paste :-
$this->session->data['shipping_timeslot'] = $this->request->post['shipping_timeslot'];
-------------------------------------------------------------------------------------------------------------
2)
Find :-
$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
After that copy and paste :-
$this->data['text_shipping_timeslot'] = $this->language->get('text_shipping_timeslot');
$this->data['ship_slot_one'] = $this->language->get('ship_slot_one');
$this->data['ship_slot_two'] = $this->language->get('ship_slot_two');
$this->data['ship_slot_three'] = $this->language->get('ship_slot_three');
$this->data['ship_slot_four'] = $this->language->get('ship_slot_four');
-------------------------------------------------------------------------------------------------------------
3)
Find :-
if (isset($this->session->data['comment'])) {
$this->data['comment'] = $this->session->data['comment'];
} else {
$this->data['comment'] = '';
}
After that copy and paste :-
if (isset($this->session->data['shipping_timeslot'])) {
$this->data['shipping_timeslot'] = $this->session->data['shipping_timeslot'];
} else {
$this->data['shipping_timeslot'] = '';
}
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
C:\wamp\www\OC\catalog\model\checkout\order.php
1)
Find :-
commission = '" . (float)$data['commission'] . "'
After that copy and paste :-
shipping_time_slot = '" . $this->db->escape($data['shipping_timeslot']) . "',
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
C:\wamp\www\OC\catalog\language\english\checkout\checkout.php
1)
Find :-
$_['text_length']
After that copy and paste :-
$_['text_shipping_timeslot'] = 'Please select the preferred shipping time slot.';
$_['ship_slot_one'] = 'Morning';
$_['ship_slot_two'] = 'Afternoon';
$_['ship_slot_three'] = 'Evening';
$_['ship_slot_four'] = 'Night';
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
C:\wamp\www\OC\catalog\view\theme\vitalia\template\checkout\shipping_method.tpl
1)
Find :-
<p><?php echo $text_shipping_method; ?></p>
Above that copy and paste :-
<p><?php echo $text_shipping_timeslot; ?></p>
<table class="radio">
<tr>
<td colspan="3"><b><?php echo "Delivery time slot"; ?></b></td>
</tr>
<tr class="highlight">
<td>
<input type="radio" name="shipping_timeslot" value="<?php echo $ship_slot_one; ?>" id="morning" checked="checked"/><?php echo $ship_slot_one; ?></br>
<input type="radio" name="shipping_timeslot" value="<?php echo $ship_slot_two; ?>" id="afternoon"/><?php echo $ship_slot_two; ?></br>
<input type="radio" name="shipping_timeslot" value="<?php echo $ship_slot_three; ?>" id="evening"/><?php echo $ship_slot_three; ?></br>
<input type="radio" name="shipping_timeslot" value="<?php echo $ship_slot_four; ?>" id="night"/><?php echo $ship_slot_four; ?></br>
</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
</table>
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
C:\wamp\www\OC\admin\controller\sale\order.php
1)
Find :-
$this->data['store_url'] = $order_info['store_url'];
Above that copy and paste :-
$this->data['shipping_time_slot'] = $order_info['shipping_time_slot'];
-------------------------------------------------------------------------------------------------------------
2)
Find :- May be line no. 1580
$this->data['comment'] = nl2br($order_info['comment']);
Below that copy and paste :-
$this->data['shipping_time_slot'] = $order_info['shipping_time_slot'];
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
C:\wamp\www\OC\catalog\controller\checkout\confirm.php
1)
Find :-
$data['comment'] = $this->session->data['comment'];
Below that copy and paste :-
$data['shipping_timeslot'] = $this->session->data['shipping_timeslot'];
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
C:\wamp\www\OC\admin\language\english\sale\order.php
1)
Find :-
$_['text_store_name'] = 'Store Name:';
Below that copy and paste :-
$_['text_time_slot'] = 'Time Slot:';
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
C:\wamp\www\OC\admin\view\template\sale\order_info.tpl
1)
Find :-
<tr>
<td><?php echo $text_store_name; ?></td>
<td><?php echo $store_name; ?></td>
</tr>
Below that copy and paste :-
<tr>
<td><?php echo $text_time_slot; ?></td>
<td><?php echo $shipping_time_slot ?></td>
</tr>
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
C:\wamp\www\OC\admin\model\sale\order.php
1)
Find :-
'date_modified' => $order_query->row['date_modified']
Below that copy and paste :-
,
'shipping_time_slot' => $order_query->row['shipping_time_slot']
-------------------------------------------------------------------------------------------------------------
THATS IT
-------------------------------------------------------------------------------------------------------------