2012-10-12 19 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>