Solved

How to get custom options from a Magento model?

Posted on 2010-09-13
8
851 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

776 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