title: Magento | Update Item Price in Quote Loop
body: <p>I have a bit of custom pricing that needs to be carried out for each product in an order which alters the end price of the item.</p>
  
  <p>I am using an observer with the <code>sales_quote_item_qty_set_after</code> event to ensure that the price is run each time the product is re-configured, as I haven't been able to get desired results from other events.</p>
  
  <p>The issue i'm running into is the inability to change the price of the product in the quote when looping through the quote using <code>-&gt;getAllItems()</code>.</p>
  
  <p>I know that the price can be overridden via the following for the product add events.</p>
  
  <pre><code>$_item = $obs-&gt;getQuoteItem();
  $_item = ( $_item-&gt;getParentItem() ? $_item-&gt;getParentItem() : $_item );
  $new_price = 1000;
  $_item-&gt;setCustomPrice($new_price);
  $_item-&gt;setOriginalCustomPrice($new_price);
  $_item-&gt;getProduct()-&gt;setIsSuperMode(true);
  </code></pre>
  
  <p>However, I can not find a way to do it when running through the quote items within the cart. Is this possible, or would the pricing have to be done in a different observer, and if so, which?</p>
  
  <p>Full code is below...</p>
  
  <pre><code>public function adminAddProduct(Varien_Event_Observer $obs) {
      $quote = $this-&gt;_getSession()-&gt;getQuote();
      foreach($quote-&gt;getAllItems() as $_item){
          $options = $_item-&gt;getProduct()-&gt;getTypeInstance(true)-&gt;getOrderOptions($_item-&gt;getProduct());
          $_product = $_item-&gt;getProduct();
          $sku = $options['simple_sku'];
          if ($sku) {
              $tierPrices = $_product-&gt;getTierPrice();
              $price = $_item-&gt;getPrice();
              $qty = $options['info_buyRequest']['qty'];
  
              $product = Mage::getModel('catalog/product')-&gt;loadByAttribute('sku',$sku);
              $runspeed = $product-&gt;getResource()-&gt;getAttribute('runspeed')-&gt;getFrontend()-&gt;getValue($product);
  
              $prodOpts = [];
              foreach($options['options'] as $option) {
                  $prodOpts[$option['label']] = $option['value'];
              }
  
              $index = 0;
              foreach($tierPrices as $tierPrice) {
                  if($tierPrice['price_qty'] &lt;= $qty &amp;&amp; $tierPrices[$index + 1]['price_qty'] &gt; $qty) {
                      $price = $tierPrice['price'];
                  }
                  //$prodTiers[$tierPrice['price_qty']] = $tierPrice['price'];
              }
  
              if($prodOpts['Quantity'] == 'Fixed Quantity' &amp;&amp; array_key_exists('Quantity Select', $prodOpts)){
                  $qty = str_replace(',', '', explode(" ", $prodOpts['Quantity Select'])[0]);
              } else {
                  $qty = 1;
              }
  
              $_item-&gt;setQty($qty);
              $_item-&gt;setCustomPrice($customPrice)-&gt;setOriginalCustomPrice($customPrice);
  
              $new_price = 999;
  
              $_item-&gt;setPrice($new_price);
              $_item-&gt;setCustomPrice($new_price);
              $_item-&gt;setOriginalCustomPrice($new_price);
              $_item-&gt;save();
  
              Mage::log($price);
              Mage::log($prodOpts);
          }
      }
  }
  </code></pre>
  
  <p>Any help is appreciated.</p>