2014-01-05 32 views
0

我是新來的php和opencart。但正打算設置我的網上商店。 我正在創建一個選項,用於在opencart的檢出頁面中選擇一個交付時段。 正如如下圖所示:opencart結賬頁面中的單選按鈕

enter image description here

於是,我開始寫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> 

請指導我。

+1

對於初學者來說,看代碼(HTML),這產生的 - 它甚至編譯/解析?它看起來並不像你關閉你的''標籤......(你開始'value =「後有''' - 這應該如何工作?)你是如何設置變量' $ ship_slot_one'等? – Floris

+0

您好弗洛里斯,我只是想做一些像在圖像中顯示。這看起來很好,在結帳頁面。現在我米卡住得到所選輸入的值,並存儲在分貝 –

回答

1

作爲弗洛提到 - 存在的輸入的部分>符號這是不正確我想。此外,最好將輸入的標籤放入真實的HTML 標籤中,以便在點擊該標籤時檢查複選框/收音機(點擊小複選框/收音機不太舒服)。

現在到您的保存問題:我建議在表order中創建一個新的DB列,稱爲shipping_time_slotenum('opt1', 'opt2', 'etc.')類型。這裏您將儲存您選擇的運送時間段。

現在的控制器,你不得不修改(由vQmod)的catalog/controller/checkout/shipping_method.php(另外你應該做的,訪客結賬非常相同的修改 - 不同的文件適用),並從POST接收shipping_timeslot值,並將其保存到會議以及所有其他運輸信息。

最後(但不是真的)您將不得不修改模型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
+0

感謝您的回覆.....讓我試着做你已經解釋過的......看起來很複雜......這應該是一條學習曲線: –

+0

這絕對是一條學習曲線,但我可以給你的最好(只是踢你,而不是給你最終的解決方案 - 所以你必須自己做這一切 - 這樣你就會學習最可能的)。 – shadyyx

+0

其酷,但如何獲得POST的價值order.php addOrder()函數? –

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 
     ------------------------------------------------------------------------------------------------------------- 
相關問題