0

I just updated a Magento store to 1.9.2 and now something strange is happen.

I have plugin that is recalculate the price when a product is added to the cart. The code triggers with an event observer (sales_quote_add_item)

In the product I have the possibility to upload a file. the problem is in the cart. It worked in Mage 1.9.1. but for some reason, the file is not appearing as a link, but as a serialized object in the cart.

It used to be something like: logo_green.jpg (600px x 600px)

It's now: {s:4:"type";s:9:"image/png";s:5:"title";s:14:"logo_green.png";s:10:"quote_path";s:68:"/media/custom_options/quote/l/o/355f0bb9f96e6b8ae3cb6d05b5299803.png";s:10:"order_path";s:68:"/media/custom_options/order/l/o/355f0bb9f96e6b8ae3cb6d05b5299803.png";s:8:"fullpath";s:137:"/Users/roywulms/Documents/Projecten/karakterprints/karakterprints/new/media/custom_options/quote/l/o/355f0bb9f96e6b8ae3cb6d05b5299803.png";s:4:"size";s:5:"26160";s:5:"width";i:600;s:6:"height";i:600;s:10:"secret_key";s:20:"355f0bb9f96e6b8ae3cb";s:3:"url";a:2:{s:5:"route";s:35:"sales/download/downloadCustomOption";s:6:"params";a:2:{s:2:"id";N;s:3:"key";s:20:"355f0bb9f96e6b8ae3cb";}}}

When I remove my plugin, it's working again.

This my observer code:

public function changingPrice(Varien_Event_Observer $observer){

    $event = $observer->getEvent();
    $quote_item = $event->getQuoteItem();
    $product = $quote_item->getProduct();
    $quantity = ($product->getQty()) ? $product->getQty() : $quote_item->getQty();
    $options = $this->getProductOptions($quote_item);
    if(sizeof($options) > 0)
    {
        $basePrice = $product->getPrice();
        foreach($options as $option)
        {
          $basePrice = ($basePrice + $option['price']);

            if($option['option_type'] == 'height')
                $heightVal =  $option['value'];
            if($option['option_type'] == 'width')
                $widthVal =  $option['value'];
        }


        $dimensionsPrice =  Mage::getModel('catalog/product')->load($product->getId())->getData('dimension_price');

        if(isset($heightVal) && isset($widthVal)){
          $meter = $basePrice + ($widthVal * $heightVal)*$dimensionsPrice;
          $new_price = $meter*$quantity;
          $quote_item->setOriginalCustomPrice($new_price);
        }
    }
 }

public function getProductOptions(&$item)
{
  $options = array();

  if ($optionIds = $item->getOptionByCode('option_ids')) {
    $options = array();
    foreach (explode(',', $optionIds->getValue()) as $optionId) {
      if ($option = $item->getProduct()->getOptionById($optionId)) {

        $quoteItemOption = $item->getOptionByCode('option_' . $option->getId());

        $group = $option->groupFactory($option->getType())
        ->setOption($option)
        ->setQuoteItemOption($quoteItemOption);

        $options[] = array(
          'label' => $option->getTitle(),
          'value' => $group->getFormattedOptionValue(unserialize($quoteItemOption->getValue()),
            'print_value' => $group->getPrintableOptionValue($quoteItemOption->getValue()),
            'price'=> $group->getOptionPrice($quoteItemOption->getValue(),0),
            'option_id' => $option->getId(),
            'option_type' => $option->getType(),
            'custom_view' => $group->isCustomizedView()
            );
        }
      }
    }
    if ($addOptions = $item->getOptionByCode('additional_options')) {
      $options = array_merge($options, unserialize($addOptions->getValue()));
    }
    return $options;
  }
}

How the code is triggered in config.xml:

 <events>
    <sales_quote_add_item>
        <observers>
           <Roywulms_Dimensioncalculator_Model_Observer>
              <type>singleton</type>
              <class>Roywulms_Dimensioncalculator_Model_Observer</class>
              <method>changingPrice</method>
           </Roywulms_Dimensioncalculator_Model_Observer>
       </observers>
   </sales_quote_add_item>
</events>

What's wrong?

0

Ok, finally found the solution:

In the getProductOptions() function, change

$group = $option->groupFactory($option->getType())
                      ->setOption($option)
                      ->setQuoteItemOption($quoteItemOption);

to

$group = $option->groupFactory($option->getType())
                    ->setOption($option)
                    ->setConfigurationItem($item)
                    ->setConfigurationItemOption($itemOption);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.