在结帐购物车mornitor中,我在购物车中添加了earch产品的日期选择器,以允许使用日期(从现在开始的1个月内)选择开始。 我想在点击下单时将此日期选择器保存到一个页面。它将保存到订单。 我已经在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但是start_date是空的
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>
我正在尝试这篇文章,但没有运气!
对不起,我的E不太好!
答案 0 :(得分:0)
几天前,我很努力,知道: - 覆盖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>
添加包含评论的列。应用程序/设计/ adminhtml /默认/缺省的/模板/销售/订单/视图/项目/渲染/ 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>
请注意:在您的主题中,对于文件:template / checkout / cart.phtml 添加新标题以及购物车项目的其他标题,并在文件中:template / checkout / cart / item / default.phtml使用datepicker选择日期,代码如下:
<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>