OK this is probably a really simple thing and I am probably missing something really simple.

I am producing price lists and getting data from magento to print the prices in tables for products in choosen category. Everything works fine for me and the price and option price with option name are listed perfectly in the table row.

However One of the options we have on our products is a colour and in magento it is set as a custom option text field. If the field is filled in by the customer a set charge is added to the product.

Now when I list the options in the table the price and the option value name wont show up.

Here is my code :


require_once('../../app/Mage.php'); //Path to Magento

function priceList($catId)

$Category = Mage::getModel('catalog/category')->load($catId);

$catName = $Category->getName();

$products = Mage::getModel('catalog/category')->load($catId)
    ->addAttributeToSelect('*')// add all attributes - optional
    ->addAttributeToFilter('status', 1)// enabled
    ->addAttributeToFilter('visibility', 4)//visibility in catalog,search
    ->addAttributeToFilter('price', array('gt' => 0.1))
    ->setOrder('position', 'ASC'); //sets the order by price

    $c = '';
    $pCnt = 0;
    $tBody = "";
    $tBottom = "";

    $c.=  "<div class='cat-heading'><b>" . $catName . "</b></div>";

    foreach ($products as $_product):

        $p = Mage::getModel('catalog/product')->load($_product->getId());
        $prodId = $p->getId();

        if ($pCnt < 1) {
            #### only generate table head for first category product
            $tTop = "<table class='general-table'>";
            $tTop .= "<tr><th>Product Name</th>";
            $tTop.= "<th>Price</th>";

            foreach ($p->getOptions() as $_option) {
                $optionName = $_option->getTitle();
                $tTop .= "<th style='font-style: italic;'>" . $optionName . "</th>";


            $tTop .= "</tr>"; // end table head

        $tBody .= "<tr>";
        $tBody .= "<td><b>" . $p->getName() . "</b></td>";
        $tBody .= "<td><b>" . number_format($p->getPrice()) . "</b></td>";

        foreach ($p->getOptions() as $_option) {

            $values = $_option->getValues();

            ///// this actually will get the colour price !! but when I use it in the values loop it is blank ?? 
            $getColourPrice = $_option->getData('default_price');   /// THE PROBLEM ONE !!!!!!!

            $tBody .= "<td>";
            $tBody .= "<table>";
            $tBody .= "<tr>";

                foreach ($values as $v) {
                    if($v->getPrice()==0) {
                        $tBody .= "&#10004"; // show tick to say this is standard
                        $tBody .= "</br> " . $v->getTitle() . "</td>";

                    } else {
                        $tBody .= $getColourPrice; //// this is always blank
                        $tBody .= number_format($v->getData('default_price'),2); // show price as this is a choosable option
                        $tBody .= "</br> " . $v->getTitle() . "</td>";

            $tBody .= "</tr>";
            $tBody .= "</table>";


        $tBody .= "</tr>";
        $tEnds .= "</table>";


    $result = $c . $tTop . $tBody . $tEnd;

return $result;


echo priceList(72);


So the problem is how do you get the value name and price for a custom product option which is a text field, I am at a complete loss and have been searching for days.

Any help would be greatly appreciated

1 Answer 1


I think the data you need is accesible directly from the option itself, check if this it's valid for you:

if ($_option->getPrice() == 0) {
  $tBody .= "&#10004"; // show tick to say this is standard
  $tBody .= "</br> " . $_option->getTitle() . "</td>";
} else {
  $tBody .= $getColourPrice; //// this is always blank
  $tBody .= number_format($_option->getData('default_price'),2); // show price as this is a choosable option
  $tBody .= "</br> " . $_option->getTitle() . "</td>";
  • thanks ander but its not working :) I will post solution on here when I find it Feb 7, 2017 at 9:37
  • I've tested now and I think it's good, the text field options doesn't have values so $values = $_option->getValues(); will allways be empty, can you debug if $values return an array? So you could use my snippet when $_option->getType == 'field'
    – Ander
    Feb 7, 2017 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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