Magento 产品开始使用时间(许可证类型)
在checkout cart mornitor中,我为cart中的earch产品添加了一个日期选择器,以允许用户选择开始使用日期(从现在起1个月内)。 我想在单击下订单时将此日期选择器保存到一页。它将按顺序保存。 我已经在eav_属性中创建了属性。 在config.xml中,我使用以下代码:Magento 产品开始使用时间(许可证类型),magento,date,using,Magento,Date,Using,在checkout cart mornitor中,我为cart中的earch产品添加了一个日期选择器,以允许用户选择开始使用日期(从现在起1个月内)。 我想在单击下订单时将此日期选择器保存到一页。它将按顺序保存。 我已经在eav_属性中创建了属性。 在config.xml中,我使用以下代码: <events> <controller_action_predispatch_checkout_cart_index >
<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>
在cart/item/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>
:
几天前,我很努力,我知道:
-覆盖app/code/core/Mage/Checkout/Model/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文件:
app/design/adminhtml/default/default/template/sales/order/view/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>
<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>
以及添加带有注释的列。app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml
在状态列之前添加一个项目注释突出列,使其看起来如下图所示
<td><?php echo $this->getLicense_start_date($_item) ?></td> <!-- New column added for item comments -->
<td class="a-center"><?php echo $_item->getStatus() ?></td>
注意:在您的主题中,对于文件:template/checkout/cart.phtml
将新标题与购物车项目的其他标题一起添加到文件中:template/checkout/cart/item/default.phtml use datepicker to selected date,代码如下:
<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>
<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>
将此日期选择器作为自定义选项包含在实际产品页面上,并将其与报价中的项目一起保存可能会更容易。这样,datepicker将在结账时自动完成,并自动保存在订单中。