2012-10-12 20 views
0

在結帳購物車mornitor中,我爲購物車中的earch產品添加了一個日期選擇器,允許客戶選擇使用日期(從現在開始1個月內)。 我想在點擊訂單時將此日期選擇器保存到onepage。它會保存到訂單。 我已經在eav_attribute中創建了屬性。 在config.xml中我使用此代碼:開始使用產品的時間(許可證類型)

<events> 

      <controller_action_predispatch_checkout_cart_index > 
       <observers> 
        <licensetime_observer> 
         <class>licensetime/observer</class> 
         <method>saveLicensetime</method> 
        </licensetime_observer> 
       </observers> 
      </controller_action_predispatch_checkout_cart_index> 

     </events> 

和觀察員我在嘗試的var_dump但起始日期爲空

public function saveLicensetime($observer) 
    { 

     $event = $observer->getEvent(); 
     $product = $event->getProduct(); 
     $quote = Mage::getSingleton('checkout/type_onepage')->getQuote(); 
     $licenseStartDate = $quote->getLicense_start_date(); 
     if (!$licenseStartDate) { 
      $licenseStartDate = date ("Y-m-d H:i:s", floor(time()/86400)*86400); 
     } 
     //var_dump($quote); die("aaaaaaaaaaa"); 

    } 

在車/項目/ defaul.phtml日期選擇器代碼:

<label for="license_start_date"><?php echo $this->__('Start Date') ?> :</label> 
    <input name="cart[<?php echo $_item->getId() ?>][license_start_date]" readonly="true" id="license_start_date<?php echo $_item->getProductId(); ?>" value="<?php echo $this->getLicenseStartTime($_item->getId()) ?>" class="date-picker" /> 
    <label for="license_end_date"><?php echo $this->__('End Date') ?> :</label> 
    <input readonly="true" name="cart[<?php echo $_item->getId() ?>][license_end_date]" id="license_end_date<?php echo $_item->getProductId(); ?>" value="<?php echo $this->getLicenseEndTime($_item->getId()) ?>"></input> 

我在嘗試這篇文章,但沒有運氣!

Magento change Custom Option value before adding it to cart

對不起,我的電子不能很好!

+0

它可能會更容易包含實際的產品頁面自定義選項在這個日期選擇器,並把它保存在報價的項目。這樣日期選擇器將通過結賬自動完成,並自動保存在訂單中。 – 1000Nettles

回答

0

前幾天之後,我很勤勞知道: - 覆蓋應用程序/代碼/核心/法師/結帳/型號/ Cart.php和編輯功能,像:

public function updateItems($data) 
{ 
    Mage::dispatchEvent('checkout_cart_update_items_before', array('cart'=>$this, 'info'=>$data)); 

    foreach ($data as $itemId => $itemInfo) { 

     $item = $this->getQuote()->getItemById($itemId); 
     if (!$item) { 
      continue; 
     } 

     if (!empty($itemInfo['remove']) || (isset($itemInfo['qty']) && $itemInfo['qty']=='0')) { 
      $this->removeItem($itemId); 
      continue; 
     } 

     $qty = isset($itemInfo['qty']) ? (float) $itemInfo['qty'] : false; 
     if ($qty > 0) { 
      $item->setQty($qty); 
     } 

    /* Start: Custom code added for license start date */ 
    if(!empty($itemInfo['license_start_date'])) { 

     $write = Mage::getSingleton('core/resource')->getConnection('core_write'); 

     # make the frame_queue active 
     $query = "UPDATE `sales_flat_quote_item` SET license_start_date = '".$itemInfo['license_start_date']."' where item_id = $itemId"; 
$write->query($query); 

     $item->setLicense_start_date($itemInfo['license_start_date']); 
    } 
    /* End: Custom code added for licensee start date */ 

    } 

    Mage::dispatchEvent('checkout_cart_update_items_after', array('cart'=>$this, 'info'=>$data)); 
    return $this; 
} 

並將app/code/core/Mage/Adminhtml/Block/Sales/Order/Items/Abstract.php複製到本地(app/code/local/Mage/Adminhtml/Block/Sales/Order/Items/Abstract.php)這個功能:

public function getLicense_start_date($item) { 
     $itemId = $item->getId(); 

     $write = Mage::getSingleton('core/resource')->getConnection('core_write'); 

     $query = "SELECT q.* FROM `sales_flat_order_item` o 
     LEFT JOIN `sales_flat_quote_item` q on o.quote_item_id = q.item_id 
     WHERE o.item_id = $itemId"; 

     # For older versions of Magento 
/*  $query = "SELECT q.* FROM `sales_order_entity_int` o 
     LEFT JOIN `sales_flat_quote_item` q on o.value = q.entity_id 
     WHERE o.entity_id = $itemId AND o.attribute_id = 343";  */  

     $res = $write->query($query); 

     while ($row = $res->fetch()) { 
      if(key_exists('itemcomment',$row)) { 
       echo nl2br($row['itemcomment']); 
      } 
     } 
    }  

要將許可證的時間列添加到項目編輯下面的一個.phtml文件: 一PP /設計/ adminhtml /默認/缺省的/模板/銷售/訂單/視圖/ items.phtml(您可以在adminhtml添加你的主題編輯)

增加頭部的項目,使它看起來象下面這樣:

<tr class="headings"> 
<th><?php echo $this->helper('sales')->__('Product') ?></th> 
<th><?php echo $this->helper('sales')->__('Licens Time') ?></th> 
<th><?php echo $this->helper('sales')->__('Item Status') ?></th> 

並添加帶註釋的列。 app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml 在狀態欄之前添加項目註釋juts的列,使其看起來像下圖所示。

<td><?php echo $this->getLicense_start_date($_item) ?></td> <!-- New column added for item comments --> 
<td class="a-center"><?php echo $_item->getStatus() ?></td> 

需要注意的是:在你的主題,該文件:模板/結算/ cart.phtml 添加新的標題與其他前往購物車的物品和文件沿:模板/結帳/車/項目/ default.phtml使用日期選擇器選定的日期代碼象下面這樣:

<td class="a-center"> 
<input type="text" name="cart[<?php echo $_item->getId() ?>][license_start_date]" rows="3" cols="20"><?php echo $_item->getLicense_start_date() ?></input> 
</td>