0

在结帐购物车 mornitor 中,我为购物车中的每个产品添加了一个日期选择器,以允许客户选择开始使用日期(从现在起 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");

    }

在 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>

我正在尝试这篇文章,但没有运气!

Magento 在将其添加到购物车之前更改自定义选项值

对不起,我的E不好!

4

1 回答 1

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>

并添加带有评论的列。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 使用 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>
于 2012-10-15T10:52:25.313 回答