2012-08-26 89 views
0

我正在開發一款首飾網站(由magento 1.7開發),其中有一款戒指產品。在戒指產品的詳細信息頁面上,我的客戶想要顯示一個用戶將輸入尺寸相關詳細信息的文本框。Magento:在自定義尺寸的產品詳細信息頁面上添加textboxx

該產品的價格不會根據所輸入的尺寸而有所不同,這個尺寸字段僅供客戶參考,以便他們可以根據用戶需要製作適當尺寸的戒指。

我已檢查,但magento不允許在可配置產品上使用文本框。

是否有人知道任何擴展名(免費或付費)或任何代碼可以幫助我在magento中實現此功能。

謝謝。

回答

1

在您的主題中,對於文件:template/checkout/cart.phtml 添加新標題以及購物車項目的其他標題。

1 
<th><?php echo $this->__('Comments') ?></th> 
In the file: template/checkout/cart/item/default.phtml 

添加新欄

1 
<td class="a-center"> 
2 
<textarea name="cart[<?php echo $_item->getId() ?>][comments]" rows="3" cols="20"><?php echo $_item->getItemcomment() ?></textarea> 
3 
</td> 

對於Magento的舊版本將是:

1 
<td class="a-center"> 
2 
<textarea name="cart[<?php echo $_item->getId() ?>][comments]" rows="3" cols="20"><?php echo $this->getItemItemcomment($_item) ?></textarea> 
3 
</td> 

下一步是保存在DB的評論,當客戶更新車。

因此,在表格'sales_flat_quote_item'中添加一個新字段'itemcomment'。 (對於舊版本的Magento,表格將爲'sales_quote_item')

現在我們將添加將執行數據庫操作的代碼。爲此,我們將需要修改文件: app/code/core/Mage/Checkout/Model/Cart.php(注意:如果您打算升級您的Magento安裝程序,請將此文件複製到本地&修改。)

在這裏我們需要添加一些代碼的功能updateItems(),這樣該函數現在看起來應該如下:

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

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

07 
     $item = $this->getQuote()->getItemById($itemId); 
08 
     if (!$item) { 
09 
      continue; 
10 
     } 
11 

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

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

22 
    /* Start: Custom code added for comments */ 
23 
    if(!empty($itemInfo['comments'])) { 
24 

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

27 
     # make the frame_queue active 
28 
     $query = "UPDATE `sales_flat_quote_item` SET itemcomment = '".$itemInfo['comments']."' where item_id = $itemId"; 
29 
     $write->query($query); 
30 

31 
     $item->setItemcomment($itemInfo['comments']); 
32 
    } 
33 
    /* End: Custom code added for comments */ 
34 

35 
    } 
36 

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

顯示在管理評論 - >查看訂單

添加新功能getItemcomment()以下文件: app/code/core/Mage/Adminhtml/Block/Sales/Order/View/It ems.php

如果您使用的是版本1.5或更高版本,請將其添加到下面的文件中。 應用程序/代碼/核心/法師/ Adminhtml /座/銷售/ /查看/ Items.php

01 
    public function getItemcomment($item) { 
02 
     $itemId = $item->getId(); 
03 

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

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

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

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

17 
     while ($row = $res->fetch()) { 
18 
      if(key_exists('itemcomment',$row)) { 
19 
       echo nl2br($row['itemcomment']); 
20 
      } 
21 
     } 
22 
    } 
To add the comments column to the items edit the .phtml file below: 
app/design/adminhtml/default/default/template/sales/order/view/items.phtml 

Adding header for items to make it look like below: 

1 
. 
2 
. 
3 
<tr class="headings"> 
4 
    <th><?php echo $this->helper('sales')->__('Product') ?></th> 
5 
    <th><?php echo $this->helper('sales')->__('Comments') ?></th> 
6 
    <th><?php echo $this->helper('sales')->__('Item Status') ?></th> 
7 
. 
8 
. 
9 
. 
Adding Column with comments. app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml 
Add a column for item comments juts before status columns to make it look a like below. 

view sourceprint? 
1 
. 
2 
. 
3 
<td><?php echo $this->getItemcomment($_item) ?></td> <!-- New column added for item comments --> 
4 
<td class="a-center"><?php echo $_item->getStatus() ?></td> 
5 
. 
6 
. 

這樣做高達這將顯示在項目表註釋列。 這將添加一個文本框作爲註釋的名稱(儘快更改名稱)。希望這有助於。 注意:只有當物品被添加到購物車時,這將會添加一個箱子,正如您所說價格不會改變,我認爲這會更合適。

+0

可以在產品詳細頁面上添加相同的商品嗎?就好像它只在購物車頁面上可見,然後用戶首先將該物品添加到購物車,然後他們將從購物車頁面添加他們的戒指尺寸詳細信息,這將是兩個步驟的過程。 – Prashant

+2

在magento中有一個錯誤,它可以防止內置的功能或錯誤導致的錯誤。我花了超過2周的時間來研究這個問題,但沒有用處相信我。如果你找到解決方案,請在這裏分享。作爲indiaplaza的magento開發者。 – user1613360

1

我已按照您的指示在我的onepage結帳中添加了評論框,但是在檢查時沒有在數據庫表中添加評論。你能告訴我我是否做錯了什麼。

下面

是我Cart.php文件,你說更新功能:

公共職能updateItems($數據) { 法師:: dispatchEvent( 'checkout_cart_update_items_before',陣列( '購物車'=> $ this,'info'=> $ data));

/* @var $messageFactory Mage_Core_Model_Message */ 
    $messageFactory = Mage::getSingleton('core/message'); 
    $session = $this->getCheckoutSession(); 
    $qtyRecalculatedFlag = false; 
    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); 

      $itemInQuote = $this->getQuote()->getItemById($item->getId()); 

      if (!$itemInQuote && $item->getHasError()) { 
       Mage::throwException($item->getMessage()); 
      } 

      if (isset($itemInfo['before_suggest_qty']) && ($itemInfo['before_suggest_qty'] != $qty)) { 
       $qtyRecalculatedFlag = true; 
       $message = $messageFactory->notice(Mage::helper('checkout')->__('Quantity was recalculated from %d to %d', $itemInfo['before_suggest_qty'], $qty)); 
       $session->addQuoteItemMessage($item->getId(), $message); 
      } 
     } 


     /* Start: Custom code added for comments */ 
     if(!empty($itemInfo['comments'])) { 

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

      # make the frame_queue active 
      $query = "UPDATE `mgn_sales_flat_quote_item` SET itemcomment = '".$itemInfo['comments']."' where item_id = " . $itemId . ""; 
      $write->query($query); 
      $item->setItemcomment($itemInfo['comments']); 

     } 
     /* End: Custom code added for comments */ 


    } 

    if ($qtyRecalculatedFlag) { 
     $session->addNotice(
      Mage::helper('checkout')->__('Some products quantities were recalculated because of quantity increment mismatch') 
     ); 
    } 

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

這不應該作爲答案發布,而應作爲給定答案的評論,答覆者可能不需要您重新粘貼所有代碼。 –

+0

下次您應該將其他問題添加爲評論,而不是將問題發佈爲答案 – acutesoftware

相關問題