Solved

How to get custom options from a Magento model?

Posted on 2010-09-13
8
857 Views
Last Modified: 2012-05-10
I have tried to use getCustomOptions but it returns a bunch of garbage. Does anyone know how I can get the custom options from a product being added to the cart? I am making a custom module and need to check if certain custom options were chosen to calculate my final cost.
0
Comment
Question by:darrenl
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:p_nuts
ID: 33665177
how does the garbage look .. you might need unserialize it
0
 

Author Comment

by:darrenl
ID: 33665200
I have used print_r on it. I am trying to get the product's custom options that are defined when I created the product.
0
 
LVL 13

Expert Comment

by:p_nuts
ID: 33665658
can you post an example
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:darrenl
ID: 33665721
This is my custom extension:
<?php
class IdeaExpress_SetupFee_Model_Quote_item extends Mage_Sales_Model_Quote_Item {
      public function calcRowTotal() {
            parent::calcRowTotal();
            
            $product = $this->getProduct();
            $product->load($product->getId());
                        
            $baseTotal = $this->getBaseRowTotal() + $product->getSetupFee();
            
            $total = $this->getStore()->convertPrice($baseTotal);
            $this->setRowTotal($this->getStore()->roundPrice($total));
            $this->setBaseRowTotal($this->getStore()->roundPrice($baseTotal));
            return $this;
      }
}
?>

I want to add logic so if a custom option is set I can multiple $product->getSetupFee.

The custom options are product options.

Thanks,
Darren
0
 
LVL 13

Expert Comment

by:p_nuts
ID: 33665804
no I mean the print_r
0
 

Author Comment

by:darrenl
ID: 33666164
The print_r was printing the wrong variable. Do you know the correct way to get custom product options in Magento?
0
 
LVL 12

Accepted Solution

by:
miked2004 earned 500 total points
ID: 33672325
have you tried:
1. $product->getOptions();
2. $product->getCustomOptions();

Look at /app/code/core/Mage?catalog/Model/product.php
0
 

Author Closing Comment

by:darrenl
ID: 33703556
This involves a lot more than these methods.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often people are aiming at development of perfect Magento websites. Though, it is easier said than done. You know what’s much easier? To ruin everything. It can be done in seconds. Many of us experimented with design, tried to change some values dir…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question