久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Magento - 根據(jù)用戶輸入報(bào)價(jià)/訂購(gòu)產(chǎn)品項(xiàng)目屬性

Magento - Quote/order product item attribute based on user input(Magento - 根據(jù)用戶輸入報(bào)價(jià)/訂購(gòu)產(chǎn)品項(xiàng)目屬性)
本文介紹了Magento - 根據(jù)用戶輸入報(bào)價(jià)/訂購(gòu)產(chǎn)品項(xiàng)目屬性的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

總結(jié)

我想創(chuàng)建一個(gè)不保存到產(chǎn)品中的產(chǎn)品屬性,或者像普通產(chǎn)品屬性一樣顯示在產(chǎn)品編輯頁(yè)面上.相反,我希望將其保存到訂單/報(bào)價(jià)項(xiàng)目并顯示在訂單、發(fā)票等上.在將產(chǎn)品添加到購(gòu)物車之前,客戶還應(yīng)該在前端對(duì)其進(jìn)行配置.

I want to create a product attribute that is not saved to products, or displayed on the product edit page like ordinary product attributes. Instead I want it to be saved to order/quote items and displayed on orders, invoices and such. It should also be configurable by the customer in the frontend before adding a product to the cart.

詳情

  • 就像自定義選項(xiàng)一樣,應(yīng)將表單元素添加到前端產(chǎn)品頁(yè)面.
    • 自定義選項(xiàng)不同,這不是實(shí)際的產(chǎn)品屬性.它不應(yīng)顯示在管理產(chǎn)品頁(yè)面或?qū)傩约?
    • 客戶需要提供有效值.我需要能夠進(jìn)行服務(wù)器端驗(yàn)證.
    • 我想要一個(gè) .phtml 模板來(lái)生成它的 html.目前我能夠以令人滿意的(設(shè)計(jì))結(jié)果覆蓋 app/design/frontend/base/default/catalog/product/view/type/default.phtml.但是,我不知道如何捕獲、驗(yàn)證并最終保存其價(jià)值.
    • Just like with Custom Options, a form element should be added to the frontend product page.
      • Unlike Custom Options, this is not an actual product attribute. It should not be displayed on the admin product pages or attribute sets.
      • The customer is required to provide a valid value. I need to be able to do server-side validation.
      • I want to have a .phtml template generating its html. Currently I'm able to override app/design/frontend/base/default/catalog/product/view/type/default.phtml with satisfactory (design) results. However I don't know how to capture, validate and eventually save its value.
      • 該值應(yīng)顯示在所有發(fā)票、訂單、銷售電子郵件中.
      • 我想用模板控制輸出,或者至少能夠返回用于顯示值的字符串

      我的問(wèn)題

      1. 如何在產(chǎn)品添加到購(gòu)物車時(shí)驗(yàn)證并最終將前端產(chǎn)品頁(yè)面上的 中的值保存到報(bào)價(jià)項(xiàng)中,然后在結(jié)帳過(guò)程中以訂單項(xiàng)目?
      2. 如何在訂單、發(fā)票、銷售電子郵件和此類頁(yè)面上顯示此值?
      3. 如何過(guò)濾訂單集合以獲取包含我的值設(shè)置為特定值的項(xiàng)目的訂單?
      1. How do I validate and eventually save the value from a <input> on the frontend product page to the quote item when the product is added to the cart, and later in the checkout process to the order item?
      2. How do I display this value on the order, invoice, sales emails and such pages?
      3. How do I filter an order collection to fetch orders that has items with my value set to a specific value?

      更新 1

      我發(fā)現(xiàn)我可以在 sales_quote_item_qty_set_after 等事件期間在 catalog/product 模型(可能還有 sales/quote_item)上運(yùn)行此代碼

      I've discovered that I can run this code on a catalog/product model (and probably sales/quote_item as well) during events such as sales_quote_item_qty_set_after

      $infoBuyRequest = $product->getCustomOption('info_buyRequest');
      $buyRequest = new Varien_Object(unserialize($infoBuyRequest->getValue()));
      $myData = $buyRequest->getMyData();
      

      通過(guò)這種方式,我能夠從產(chǎn)品頁(yè)面上的 <input> 中檢索自定義的、客戶提供的數(shù)據(jù).

      In this way I was able to retrieve my custom, customer supplied, data from my <input> on the product page.

      我懷疑此 info_buyRequest 與報(bào)價(jià)和訂單項(xiàng)目一起保存.如果是這樣,這部分解決了我的問(wèn)題 1 和 2.但是,我仍然不知道在哪里運(yùn)行這段代碼是合適的,我也不知道如何在后端訂單/報(bào)價(jià)/報(bào)告頁(yè)面上顯示它.我也相信,因?yàn)樗亲鳛樾蛄谢荡鎯?chǔ)在數(shù)據(jù)庫(kù)中的,所以根據(jù)我的自定義數(shù)據(jù)獲取報(bào)價(jià)/訂單項(xiàng)目集合將是最困難的.

      I suspect this info_buyRequest is saved with the quote and order items. If so, this partially solved my problems 1 and 2. However, I still dont know where it's suitable to run this code, and I dont know how to display it on the backend order/quote/report pages. Also I belive since this is stored as a serialized value in the database, it will be most difficult to get quote/order item collections based on my custom data.

      推薦答案

      Magento 提供了添加選項(xiàng)的功能,這些選項(xiàng)不是產(chǎn)品屬性或產(chǎn)品自定義選項(xiàng).它們通過(guò)選項(xiàng)代碼 additional_options 在產(chǎn)品和報(bào)價(jià)項(xiàng)目上設(shè)置.

      Magento provides a capability for adding options that aren't product attributes or product custom options. They are set on the product and quote items with the option code additional_options.

      您需要執(zhí)行兩個(gè)步驟,每個(gè)步驟都可以通過(guò)事件觀察器進(jìn)行處理.如果您希望其他選項(xiàng)通過(guò)重新排序進(jìn)行,您還需要觀察第三個(gè)事件.

      There are two steps you need to take, each can be handled via an event observer. If you want the additional options to carry through reordering, you will need also observe a third event.

      第一步是添加事件觀察器,在加載的產(chǎn)品被添加到購(gòu)物車之前設(shè)置附加選項(xiàng).一種選擇是使用 catalog_product_load_after 事件.

      The first step is to add the event observer to set the additional options on the loaded product before it is added to the cart. One option is to use the catalog_product_load_after event.

      <catalog_product_load_after>
          <observers>
              <extra_options>
                  <type>model</type>
                  <class>extra_options/observer</class>
                  <method>catalogProductLoadAfter</method>
              </extra_options>
          </observers>
      </catalog_product_load_after>
      

      在事件觀察器中,您可以添加額外的檢查請(qǐng)求的頁(yè)面確實(shí)是添加到購(gòu)物車的操作.這種觀察者方法的要點(diǎn)是將您的特殊選項(xiàng)的選擇添加到產(chǎn)品模型的 additional_options 選項(xiàng)中.

      In the event observer you can add additional checks the requested page is indeed an add to cart action. The main point of this observer method is to add the selection of your special options to the additional_options option on the product model.

      public function catalogProductLoadAfter(Varien_Event_Observer $observer)
      {
          // set the additional options on the product
          $action = Mage::app()->getFrontController()->getAction();
          if ($action->getFullActionName() == 'checkout_cart_add')
          {
              // assuming you are posting your custom form values in an array called extra_options...
              if ($options = $action->getRequest()->getParam('extra_options'))
              {
                  $product = $observer->getProduct();
      
                  // add to the additional options array
                  $additionalOptions = array();
                  if ($additionalOption = $product->getCustomOption('additional_options'))
                  {
                      $additionalOptions = (array) unserialize($additionalOption->getValue());
                  }
                  foreach ($options as $key => $value)
                  {
                      $additionalOptions[] = array(
                          'label' => $key,
                          'value' => $value,
                      );
                  }
                  // add the additional options array with the option code additional_options
                  $observer->getProduct()
                      ->addCustomOption('additional_options', serialize($additionalOptions));
              }
          }
      }
      

      附加選項(xiàng)將自動(dòng)從產(chǎn)品移至報(bào)價(jià)項(xiàng).有了這個(gè)觀察者,您的選項(xiàng)就會(huì)出現(xiàn)在購(gòu)物車和結(jié)賬評(píng)論中.

      The additional options will be moved from the product to the quote item automatically. With this observer in place, your options will appear in the cart and the checkout review.

      為了讓它們持久化,需要一個(gè)額外的觀察者(僅自 Magento 1.5 起).

      In order to have them persist, one additional observer is needed (only since Magento 1.5).

      <sales_convert_quote_item_to_order_item>
          <observers>
              <extra_options>
                  <type>model</type>
                  <class>extra_options/observer</class>
                  <method>salesConvertQuoteItemToOrderItem</method>
              </extra_options>
          </observers>
      </sales_convert_quote_item_to_order_item>
      

      這里我們將選項(xiàng)從報(bào)價(jià)項(xiàng)移到訂單項(xiàng).

      Here we move the option from the quote item to the order item.

      public function salesConvertQuoteItemToOrderItem(Varien_Event_Observer $observer)
      {
          $quoteItem = $observer->getItem();
          if ($additionalOptions = $quoteItem->getOptionByCode('additional_options')) {
              $orderItem = $observer->getOrderItem();
              $options = $orderItem->getProductOptions();
              $options['additional_options'] = unserialize($additionalOptions->getValue());
              $orderItem->setProductOptions($options);
          }
      }
      

      從現(xiàn)在開始,附加選項(xiàng)將在前端的客戶訂單歷史記錄和訂單電子郵件以及管理界面訂單視圖、發(fā)票、發(fā)貨、貸項(xiàng)通知單和 PDF 中可見.

      From this point on the additional options will be visible in the customer order history in the frontend and the order emails, as well as in the admin interface order view, invoices, shipments, creditmemos and PDFs.

      為了在重新訂購(gòu)期間將 oprions 轉(zhuǎn)移到新訂單,您需要小心地將它們復(fù)制過(guò)來(lái).這是使用 checkout_cart_product_add_after 事件的一種可能性.

      In order to carry the oprions over to the new order during a reorder, you need to take care to copy them over. Here is one possibility using the checkout_cart_product_add_after event.

      <checkout_cart_product_add_after>
          <observers>
              <extra_options>
                  <type>singleton</type>
                  <class>extra_options/observer</class>
                  <method>checkoutCartProductAddAfter</method>
              </extra_options>
          </observers>
      </checkout_cart_product_add_after>
      

      額外選項(xiàng)的解析和構(gòu)建額外的選項(xiàng)數(shù)組應(yīng)該移到一個(gè)單獨(dú)的函數(shù)中以避免代碼重復(fù),但在這個(gè)例子中,為了清楚起見,我將保留每個(gè)方法所需的邏輯.

      The parsing of the extra options and building the additional options array should be moved into a separate function to avoid code duplication, but for this example I'll leave the required logic for each method in place for clarity.

      public function checkoutCartProductAddAfter(Varien_Event_Observer $observer)
      {
          $action = Mage::app()->getFrontController()->getAction();
          if ($action->getFullActionName() == 'sales_order_reorder')
          {
              $item = $observer->getQuoteItem();
              $buyInfo = $item->getBuyRequest();
              if ($options = $buyInfo->getExtraOptions())
              {
                  $additionalOptions = array();
                  if ($additionalOption = $item->getOptionByCode('additional_options'))
                  {
                      $additionalOptions = (array) unserialize($additionalOption->getValue());
                  }
                  foreach ($options as $key => $value)
                  {
                      $additionalOptions[] = array(
                          'label' => $key,
                          'value' => $value,
                      );
                  }
                  $item->addOption(array(
                      'code' => 'additional_options',
                      'value' => serialize($additionalOptions)
                  ));
              }
          }
      }
      

      翻譯:

      沒(méi)有適當(dāng)?shù)臋C(jī)制來(lái)翻譯這些選項(xiàng)標(biāo)簽或值.以下是一些可能在這方面有用的想法.

      Translation:

      There is no mechanism in place to translate these option labels or values. Here are a few ideas that might be useful in that regard.

      在 quote_item_load_after 事件觀察器中,獲取附加選項(xiàng)數(shù)組并設(shè)置 $option['print_value'] = $helper->__($option['value']);.如果設(shè)置了 print_value,Magento 將使用它來(lái)渲染顯示.
      訂單項(xiàng)也可以這樣做.

      In a quote_item_load_after event observer, get the additional options array and set $option['print_value'] = $helper->__($option['value']);. If print_value is set, Magento will use that for rendering the display.
      The same can be done with order items.

      沒(méi)有像 print_label 這樣的東西,但是您可以設(shè)置自定義索引(可能是 label_source)并使用它作為源即時(shí)設(shè)置標(biāo)簽,例如$option['label'] = $helper->__($option['label_source']);.

      There is no such thing as a print_label, but you could set a custom index (label_source maybe) and set the label on the fly using that as the source, e.g. $option['label'] = $helper->__($option['label_source']);.

      除此之外,您可能不得不求助于修改模板(grep for getItemOptions()),或覆蓋塊類(grep additional_options).

      Beyond that you would probably have to resort to modifying the templates (grep for getItemOptions()), or overriding the block classes (grep additional_options).

      這篇關(guān)于Magento - 根據(jù)用戶輸入報(bào)價(jià)/訂購(gòu)產(chǎn)品項(xiàng)目屬性的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

      【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Magento products by categories(按類別劃分的 Magento 產(chǎn)品)
Resource interpreted as image but transferred with MIME type text/html - Magento(資源被解釋為圖像但使用 MIME 類型 text/html 傳輸 - Magento)
Is there an event for customer account registration in Magento?(Magento 中是否有客戶帳戶注冊(cè)事件?)
Magento addFieldToFilter: Two fields, match as OR, not AND(Magento addFieldToFilter:兩個(gè)字段,匹配為 OR,而不是 AND)
quot;Error 404 Not Foundquot; in Magento Admin Login Page(“未找到錯(cuò)誤 404在 Magento 管理員登錄頁(yè)面)
Get Order Increment Id in Magento(在 Magento 中獲取訂單增量 ID)
主站蜘蛛池模板: 亚洲第一女人av | 国产高清精品一区二区三区 | 丝袜 亚洲 另类 欧美 综合 | 国产精品久久网 | 午夜性色a√在线视频观看9 | 国产网站在线免费观看 | 欧美黄在线观看 | 亚洲成人毛片 | 国产一区二区在线免费 | 伊人精品 | 免费在线观看毛片 | 日韩精品成人网 | 福利视频一区二区三区 | 一级h片 | 国产亚洲精品精品国产亚洲综合 | 波多野结衣一区二区三区在线观看 | 免费在线成人 | 亚洲va欧美va天堂v国产综合 | 精品国产乱码久久久久久1区2区 | 久久亚洲综合 | 爱综合 | 久久大陆 | 精品日韩一区二区三区 | 成人乱人乱一区二区三区软件 | 欧美激情久久久 | 久久国产精品一区二区 | 高清一区二区三区 | 蜜桃黄网 | 一区在线观看 | 一区二区三区在线看 | 免费网站国产 | 久久久久一区二区三区 | 欧美精品片 | 97中文视频 | 久草视频在线播放 | 国产在线激情视频 | 亚洲欧美日韩一区二区 | 国产成人91视频 | 久久久一区二区三区 | 国产一级黄色网 | 国产激情一区二区三区 |