2016-12-23 1 views
0

Привет для веб-сайта Magento мне нужно загрузить пользовательский атрибут в корзину покупок.Загрузите пользовательский атрибут в корзину Magento

Я использую функцию getmodel для загрузки элементов. но я не знаю, как загрузить атрибут. возможно, я не правильно настроил атрибут. Я включил да для включения в список продуктов. Код атрибута - «staffel_percentage». это просто обычная строка

также, когда я меняю цену за продукт, это не меняет промежуточный итог, может быть, это потому, что мы уже изменили цену продукта на остальной части сайта?

Возможно, это событие? Я использую это событие: controller_action_layout_render_before.

это код в наблюдателя я использую для него

$cart = Mage::getModel('checkout/cart')->getQuote();       // Gets the collection of checkout 
     foreach ($cart->getAllItems() as $item) {            // adds all items to $item and does the following code for each item 

      if ($item->getParentItem()) {              // If items is part of a parent 
      $item = $item->getParentItem();              // Get parentItem; 
      } 
      //echo 'ID: '.$item->getProductId().'<br />'; 

      $percentage = 80;// init first percentage 

      $quantity = $item->getQty(); //quantity 

      //$staffelstring = loadattribute//loads attribute 

      //gives the right percentage per quantity 
      //$staffelarray = explode(';', ^); 
      //foreach($staffelarray as $staffels){ 
       //$stafel = explode(':', $staffels); 
       //if($quantity >= $stafel[0]){ 
        //$percentage = $Stafel[1]; 
       //} 
      //} 


      $currency = Mage::app()->getStore()->getCurrentCurrencyRate();      // Currencyrate that is used currently 
      $specialPrice = (($this->CalculatePrice($item) * $currency)* $percentage)/100;       //New prices we want to give the products 

      if ($specialPrice > 0) {               // Check if price isnt lower then 0 
       $item->setCustomPrice($specialPrice);           //Custom Price will have our new price 
       $item->setOriginalCustomPrice($specialPrice);         //Original Custom price will have our new price, if there was a custom price before 
       $item->getProduct()->setIsSuperMode(true);          //set custom prices against the quote item 
       } 
      } 

ответ

0

Вы должны загрузить продукт сразу после первой, если заявление

$product = Mage::getModel('catalog/product')->load($item->getId()); // may be $item->getProductId() instead here 

Затем на следующей строке после этого вы можете добавить некоторые заявления о регистрации, которые появятся в var/log/system.log

Mage::log($product->getData()); // this will output all of the product data and attributes. You will see your custom attribute value here if it is set on this product. 

Если есть значение se т для вашего продукта для пользовательского атрибута, то вы можете получить его, как этот

$value = $product->getData('staffel_percentage'); 

Что касается изменения цены, не знаю, как у вас есть цены установить. Вам нужно установить положительное или отрицательное число, чтобы добавить или вычесть из цены в полях, найденных на странице конфигурации родительского продукта в Каталоге> Продукты> Ваш продукт> Ассоциированные продукты.

См. this image, для чего выглядит раздел.