Specialized Magento admin user

I’m working on a project which requires that certain people have limitted access to the admin area. I have created a new Role for this type of admin user, but I also need the following for this specific set of users:

  • A few additional fields, like “Company Name” and “Phone Number”
  • Ability to hide these users from System -> Permissions -> Users
    • They will appear in a separate grid somewhere else
  • Maintain the ability for them to login to the admin area, reset their password if forgotten, etc
  • All of these ‘specialized’ users will always have the same role.

I have the following ideas, but I’m not sure which (if any) are best practices:

  • Storing the data in the db
    • Use the extras field for storage
    • Create a new table with the same PK as the user, plus the additional fields
  • Implementing the model
    • Extend Mage_Admin_Model_User and the collection; use these within my module only instead of the standard classes
    • Extend & override the above so that all admin user objects have the functionality

My question: What approach would work best for this scenario? Maybe you have an even better idea than I do

Bonus: free internets will be given for including any sample code, tutorials, references, etc which demonstrate how to do accomplish the given approach.

Edit 1: The more I think about it, the more I feel the non-crossed-out options above would work best. My custom modules are the only ones who really need that extra functionality. The only override would be for the original user collection, to add a filter to exclude these ‘other users’ from the default user admin screens.

Add selection to bundle programatically

on import i would like to add imported products as bundled products to a list of bundle products.

I extended Mage_Catalog_Model_Convert_Adapter_Product and used this class in a custom Dataflow, before the imported row is saved the following code is executed:

//Load product model collection filtered by attribute set id        
$products = Mage::getModel('catalog/product')
                ->getCollection()
                ->addAttributeToSelect('name')
                ->addFieldToFilter('attribute_set_id', 12);

// loop through products
foreach($products as $p){
    // get product options
    $options = $p->getTypeInstance(true)->getOptionsCollection($p);
}

What i need to do next is determine what is the right option (by title), and add the product as a selection to it.

$option->addSelection($selection);

But how do i get the option title and how do i create the selection from my product?

MAGENTO 1.5: Products that generate printable PDF's

So I’ll explain this as well as I can, please feel free to ask questions if I need to clarify anything.

  • We create credentials from PDF’s.
  • The background image is already printed onto a piece of paper (A4: Landscape)
  • From inputs in our products (Custom Options > Name and Date) and an incrementing credential number which is stored in our database; we overlay these on our A4 papers at specific coordinates to print a final product ourselves.

We typically sell around 400 ~ 900 of these a day, so we would need a combined PDF sheet that
generates/adds all these to single printable document. How these are segregated from yesterdays orders
or todays orders, or orders after printing todays orders doesn’t matter. It could be by LAST credential
number, or by date/time cut-off, or whatever. It’s negligable as long as there is not duplicates.

Things I would like to see is the ability for the user to preview their credential prior to submission
(JQuery would most likely fit the bill, I envisioned updating the preview image from the input fields),
the ability to use a filter array or list (could be a flatfile?) so we can remove banned words, and lastly
so we can correct mistakes even the the user makes them, a way to edit the PDF’s, either direclty through
a tool.

I’ve been looking around for a plugin or module for the last week that I could at least get a starting
point on to do this. If not this is something that will need to be created from scratch. I looked at web
to print by Zetaprints briefly but there is not only a complicated install process, but also a pay per use
of about a $1.70 that would quickly eat into our profit margins.

What we do now
This is the old version that we used with OSCommerce that will need to be replaced by a Magento equivalent.

Old Version with Edit Capabilities: http://pastebin.com/pafG0RLZ

New Version without Editing: http://pastebin.com/b4a3kim1

Here is the physical code of the new version that would need some kind of integration. Please stop downvoting me based on “theoretical concepts” since this is already a working product that needs integration.

    case "Ordination Credentials":

        // hack -jd
        include ('class.ezpdf.php'); 
        $pdf =& new Cezpdf('LETTER','landscape'); 
        $pdf->selectFont('./fonts/mtcorsva.afm'); 
        $pdf->ezSetMargins(30,1,30,1);

            extract($_GET); 

        $query = "
                SELECT  o.date_purchased, 
                        fd.template_fn, 
                        o.customers_name, 
                        op.orders_id, 
                        opa.orders_products_id, 
                        products_name, 
                        op.products_quantity, 
                        field_name, 
                        products_options_values

                FROM orders_products AS op
                JOIN orders AS o ON o.orders_id                     = op.orders_id
                JOIN fulfillment_doc_products AS fdp ON fdp.product_id          = op.products_id
                JOIN fulfillment_docs AS fd ON fd.doc_id                = fdp.doc_id
                JOIN orders_products_attributes AS opa ON opa.orders_products_id    = op.orders_products_id

                RIGHT JOIN fulfillment_doc_fields AS fdf ON fdf.products_options_name   = opa.products_options

                    AND fdf.doc_products_id                                             = fdp.doc_products_id

                WHERE op.orders_id
                BETWEEN $in

                    AND $out
                    AND fd.doc_id                                                       = $doc_id

                ORDER BY o.orders_id, products_name, opa.orders_products_id, field_name, products_options_values";

            $result = mysql_query(trim($query)) or die("Broke the interwebs.");
            while ($query_data = mysql_fetch_array($result)) {

                //Standard db output filtering and processing into multi-dimensional array as seen above                
                $creds[$query_data['orders_products_id']][$query_data['field_name']]    = sanitize_db_output($query_data['products_options_values']);
                $creds[$query_data['orders_products_id']]['order_number']       = $query_data['orders_id'];
                $creds[$query_data['orders_products_id']]['products_quantity']      = $query_data['products_quantity'];

            }

                $started = false;

            foreach( $creds as $opt ) {
                if($started) { $pdf->ezNewPage(); } //create new page

                    $started = true;
                    $name = ucwords(strtolower($opt['name']));

                    foreach (array('-', ''',' Mc') as $delimiter) {
                        if (strpos($name, $delimiter) == true) {
                            $name = implode($delimiter, array_map('ucfirst', explode($delimiter, $name)));
                        }
                    }

                //all caps
                foreach (array('Ii', 'Iii') as $delimiter) {
                    if (strpos($name, $delimiter) == true) {
                        $name = implode($delimiter, array_map('strtoupper', explode($delimiter, $name)));
                  }
                }

                if(strpos($name, ',') !== false) { 
                    foreach (array(', Jr', ', Sr') as $delimiter) {
                        if (strpos($name, $delimiter) == false) {
                            $name=implode(" ", array_reverse(explode(',', $name)));
                        }
                    }
                }

                    $day = $opt["date-day"];

                if (0<>$day) {
                    if (in_array($day% 100, range(11,13))) {
                        $day .= 'th';
                    } else {
                        switch ( $day % 10 ) {
                            case 1:  $day .= 'st'; break;
                            case 2:  $day .= 'nd'; break;
                            case 3:  $day .= 'rd'; break;
                            default: $day .= 'th'; break;
                        }
                    }
                }

                    $month  = $opt["date-month"];
                    $year   = $opt["date-year"];
                    $ordid  = $opt["order_number"];

                //create date
                if (!isset($yname)) { $yname = "370"; }
                if (!isset($ydate)) { $ydate = "289"; }

                    $pdf->ezSetY($yname);   $pdf->ezText($name,28,array('left'=>-35, 'justification'=>'center'));
                    $pdf->ezSetY($ydate);   $pdf->ezText($day,17,array('left'=>-220, 'justification'=>'center'));
                    $pdf->ezSetY($ydate);   $pdf->ezText($month,17,array('left'=>40, 'justification'=>'center'));
                    $pdf->ezSetY($ydate);   $pdf->ezText($year,17,array('left'=>375, 'justification'=>'center'));
                    $pdf->ezSetY(96);       $pdf->ezText($ordid,12,array('left'=>505, 'justification'=>'center'));
            }

            $pdfcode = $pdf->output(); 
            $file = './tmp/PDF_ordinations.pdf';

            if (file_exists($fname)) { unlink($fname); }    //start with new file
            if (!file_exists($dir)) { mkdir ($dir,0777); }  //dir create if not there

                $fname = $file;
                $fp = fopen($fname,'w'); 

            fwrite($fp,$pdfcode); 
            fclose($fp); 

        header('Location:'.$fname);

    break;

How can I find the instance calling another Magento object's method from within that object?

A client has asked me to reduce the complexity of Magento’s …/template/checkout/cart/shipping.phtml so that it only asks for (US) Zip Code, bypassing Country and Region, and then furthermore assumes the first shipping option. (Order to be determined by client in the admin). In order to do that, I need to override the estimatePostAction method from …/Mage/Checkout/controllers/CartController.php so that it assumes the result from estimateUpdatePostAction (from the same class).

I’m stuck trying to choose the first shipping option.

The problem I’m having is that the valid shipping values are calculated in the shipping.phtml template via a loop over $this->getEstimateRates(). How can I get the object that is represented by $this from within my overriding CartController class in order to calculate the shipping options?

Note: This is Magento EE ver. 1.11.2.0

If you find the above tl;dr, here’s a summary what I’m trying to do:

  • Override checkout/cart/shipping template so that it:
    • Only asks for Zip Code
    • Automatically chooses the first available valid shipping option without asking

Magento Tier Sales Prices?

I’ve been trying to mirror some functionality
in Magento (v1.6) as seen on another website. In the example, the
store owner has set up the ability to apply sales prices to a tier.
(most likely tierprices.phtml as the wrapper) by applying a sales price
(most likely in admin / product / price sales)

I’ve been working on figuring out exactly how it is done, but haven’t
made any headway on it insofar. Does anyone have any idea how this was
constructed?

Here’s the example website
http://www.epromos.com/product/2801001.html

Here’s the Table code:

    if($_tierPrices) {
        echo '<style>
                .strikeRow      {text-decoration: line-through;}
                .saleRow td     {color:red;}
                .quantityRow    {background: #eef} 
                td              {padding:3px 9px; border: 1px solid #fc0;} 
            </style>';          // temporary styling

        $q = "<td>Quantity</td>";
        $p = "<td>{$_product->getName()}</td>";
        $s = "<td>Reduced Price</td>";

        foreach ($_tierPrices as &$tier) { 
        #$tier['tier_sale'] = '0.00';   // trick the dump into thinking there is a product sale
            if($tier['price_qty'])      { $q .= "<td>{$tier['price_qty']}</td>"; }
            if($tier['price'])          { $p .= "<td>".number_format($tier['price'], 2, '.', '')."</td>"; }
            if($tier['tier_sale'])      { $s .= "<td>{$tier['tier_sale']}</td>"; }
        }

        $q = "<tr class='quantityRow'>{$q}</tr>";
        $p = ($_tierPrices[0]['tier_sale'])? "<tr class='strikeRow'>{$p}</tr>"  : "<tr>{$p}</tr>";
        $s = ($_tierPrices[0]['tier_sale'])? "<tr class='saleRow'>{$s}</tr>"    : '';

        echo "<tbody>$q $p $s</tbody></table>";

    }

And the full source:

<?php
/**
 * @see Mage_Catalog_Block_Product_View
 */
$_product = $this->getProduct();
$_tierPrices = $this->getTierPrices();
$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);

/** @var $_catalogHelper Mage_Catalog_Helper_Data */
$_catalogHelper = Mage::helper('catalog');

$_weeeTaxAmount = Mage::helper('weee')->getAmountForDisplay($_product);

if (Mage::helper('weee')->typeOfDisplay($_product, array(1,2,4))) {
    $_weeeTaxAttributes = Mage::helper('weee')->getProductWeeeAttributesForDisplay($_product);
}

 if (count($_tierPrices) > 0) { 

    // start table group with class type if  (obj)getInGrouped() == 1
    echo ($this->getInGrouped()) ? '<table class="tier-prices-grouped product-pricing-grouped">' : '<table class="tier-prices product-pricing">'; 

    // assign tier pricing to $_tierPrices
    if ($this->getInGrouped()) {
         $_tierPrices = $this->getTierPrices($_product);
    }

        Mage::helper('weee')->processTierPrices($_product, $_tierPrices);

    foreach ($_tierPrices as $_price) {

        echo '<tr>';

        if ($_catalogHelper->canApplyMsrp($_product)) {

            if ($this->getInGrouped()) {

                echo $this->__('Buy %1$s for', $_price['price_qty']) .':';

            } else { 

                echo $this->__('Buy %1$s', $_price['price_qty']);

            } 

        } else {

                if ($this->helper('tax')->displayBothPrices()) {

                    if (Mage::helper('weee')->typeOfDisplay($_product, 0)) {

                        echo $this->__('Buy %1$s for %2$s (%3$s incl. tax) each', $_price['price_qty'], $_price['formated_price_incl_weee_only'], $_price['formated_price_incl_weee']);

                    } elseif(Mage::helper('weee')->typeOfDisplay($_product, 1)) {

                            echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);

                            if ($_weeeTaxAttributes) {

                                echo '(<small>';
                                echo $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']);

                                $separator = ' + '; 

                                    foreach ($_weeeTaxAttributes as $_attribute) {

                                        echo $separator;
                                        echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount());

                                    }

                                echo '</small>)';

                            }

                            echo $this->__('each');

                    } elseif(Mage::helper('weee')->typeOfDisplay($_product, 4)) {

                            echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);

                            if ($_weeeTaxAttributes) {

                                echo '(<small>';
                                echo $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']);

                                $separator = ' + '; 

                                    foreach ($_weeeTaxAttributes as $_attribute) {

                                        echo $separator;
                                        echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount()+$_attribute->getTaxAmount());

                                    }

                                echo '</small>)';

                            }

                            echo $this->__('each');

                    } elseif(Mage::helper('weee')->typeOfDisplay($_product, 2)) {

                            echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price']);

                            if ($_weeeTaxAttributes) {

                                echo '(<small>';

                                    foreach ($_weeeTaxAttributes as $_attribute) {

                                        echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount());

                                    }

                                echo $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']);
                                echo '</small>)';

                            }

                            echo $this->__('each');

                    } else {

                            echo $this->__('Buy %1$s for %2$s (%3$s incl. tax) each', $_price['price_qty'], $_price['formated_price'], $_price['formated_price_incl_tax']);

                    }

                } else {

                    if ($this->helper('tax')->displayPriceIncludingTax()) {

                        if (Mage::helper('weee')->typeOfDisplay($_product, 0)) {

                                echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price_incl_weee']);

                        } elseif(Mage::helper('weee')->typeOfDisplay($_product, 1)) {

                                echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee']);

                                if ($_weeeTaxAttributes) {

                                    echo '(<small>';
                                    $separator = ''; 

                                    foreach ($_weeeTaxAttributes as $_attribute) {

                                            echo $separator;
                                            echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount());

                                        $separator = ' + '; 

                                    }

                                    echo '</small>)';

                                }

                                echo $this->__('each');

                        } elseif(Mage::helper('weee')->typeOfDisplay($_product, 4)) { 

                                echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee']);

                                if ($_weeeTaxAttributes) {

                                    echo '(<small>';
                                    $separator = ''; 

                                    foreach ($_weeeTaxAttributes as $_attribute) {

                                            echo $separator;
                                            echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount()+$_attribute->getTaxAmount());

                                        $separator = ' + ';

                                    } 

                                    echo '</small>)';

                                }

                                echo $this->__('each');

                        } elseif(Mage::helper('weee')->typeOfDisplay($_product, 2)) {

                                echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_tax']);

                                if ($_weeeTaxAttributes) {

                                    echo '(<small>';

                                        foreach ($_weeeTaxAttributes as $_attribute) {

                                            echo $_attribute->getName() .': '. Mage::helper('core')->currency($_attribute->getAmount());

                                        }

                                    echo $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']);
                                    echo '</small>)';

                                }

                                echo $this->__('each');

                        } else {

                                echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price_incl_tax']);
                        }

                    } else {

                        if (Mage::helper('weee')->typeOfDisplay($_product, 0)) {

                                echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price_incl_weee_only']);

                        } elseif(Mage::helper('weee')->typeOfDisplay($_product, 1)) {

                                echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);

                                if ($_weeeTaxAttributes) {

                                    echo '(<small>';
                                    $separator = ''; 

                                        foreach ($_weeeTaxAttributes as $_attribute) {

                                            echo $separator;
                                            echo $_attribute->getName(); ?>: <?php echo Mage::helper('core')->currency($_attribute->getAmount());

                                        $separator = ' + '; 

                                        }

                                    echo '</small>)';

                                }

                                echo $this->__('each');

                        } elseif(Mage::helper('weee')->typeOfDisplay($_product, 4)) {

                                echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);

                                if ($_weeeTaxAttributes) {

                                    echo '(<small>';
                                    $separator = ''; 

                                        foreach ($_weeeTaxAttributes as $_attribute) {

                                            echo $separator;
                                            echo $_attribute->getName(); ?>: <?php echo Mage::helper('core')->currency($_attribute->getAmount()+$_attribute->getTaxAmount());

                                        $separator = ' + '; 

                                        }

                                    echo '</small>)';

                                }

                                echo $this->__('each');

                        } elseif(Mage::helper('weee')->typeOfDisplay($_product, 2)) {

                                echo $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price']);

                                if ($_weeeTaxAttributes) {

                                    echo '(<small>';

                                        foreach ($_weeeTaxAttributes as $_attribute) {

                                            echo $_attribute->getName(); ?>: <?php echo Mage::helper('core')->currency($_attribute->getAmount());

                                        }

                                    echo $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee_only']);
                                    echo '</small>)';

                                }

                                echo $this->__('each');

                        } else {

                                // concern
                                //echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price']);

                                $priceSchema['quantity'][] =  $_price['price_qty'];
                                $priceSchema['formated_price'][] =  $_price['formated_price'];

                        }


                    } 

        }


        } // Can apply MSRP

        if (!$this->getInGrouped()) {

        // we need this ~

            // funky ass OR switch, can i rework this in a saner way?
            if( ($_product->getPrice() == $_product->getFinalPrice() && $_product->getPrice() > $_price['price'])
             || ($_product->getPrice() != $_product->getFinalPrice() &&  $_product->getFinalPrice() > $_price['price']) ) {

//               echo ' '. $this->__('and') .'&nbsp;<strong class="benefit">'. $this->__('save') .'&nbsp;'. $_price['savePercent'] .'%';

            } 

//          echo '</strong>'; // why the hell isn't this in the OR switch??? 

        // we need this ~

        }

        if ($_catalogHelper->isShowPriceOnGesture($_product)) {

            $popupId = 'msrp-popup-' . $_product->getId() . $this->helper('core')->getRandomString(20);

            echo '<a href="#" id="'. $popupId .'">'. $this->__('Click for price') .'</a>';
            echo '<script type="text/javascript">';

            if (!$this->getInGrouped()) {

                echo 'var newLink = {';

                    echo 'url: "'. $this->getAddToCartUrl($_product, array('qty' => $_price['price_qty'])) .'",';
                    echo 'qty: "'. $_price['price_qty'] .'"';

                echo '};';

            } else {

                echo 'var newLink = {';

                    echo 'url: "'. $this->getAddToCartUrl($_product, array('qty' => $_price['price_qty'])) .'",';
                    echo 'notUseForm: true';

                echo '};';

            }

                echo 'Catalog.Map.addHelpLink(';

                    echo "$('{$popupId}'),";
                    echo '"'. $_product->getName() .'",';
                    echo json_encode($_price['real_price_html']) .',';
                    echo '"'. $this->helper('core')->currency($_product->getMsrp(),true,false) .'",';
                    echo 'newLink';

                echo ');';

            echo '</script>';

        } else {

            echo '<span class="msrp-price-hide-message">'. $_catalogHelper->getMsrpPriceMessage($_product) .'</span>';

        }

    }
}

    if($_tierPrices) {
        echo '<style>
                .strikeRow      {text-decoration: line-through;}
                .saleRow td     {color:red;}
                .quantityRow    {background: #eef} 
                td              {padding:3px 9px; border: 1px solid #fc0;} 
            </style>';          // temporary styling

        $q = "<td>Quantity</td>";
        $p = "<td>{$_product->getName()}</td>";
        $s = "<td>Reduced Price</td>";

        foreach ($_tierPrices as &$tier) { 
        #$tier['tier_sale'] = '0.00';   // trick the dump into thinking there is a product sale
            if($tier['price_qty'])      { $q .= "<td>{$tier['price_qty']}</td>"; }
            if($tier['price'])          { $p .= "<td>".number_format($tier['price'], 2, '.', '')."</td>"; }
            if($tier['tier_sale'])      { $s .= "<td>{$tier['tier_sale']}</td>"; }
        }

        $q = "<tr class='quantityRow'>{$q}</tr>";
        $p = ($_tierPrices[0]['tier_sale'])? "<tr class='strikeRow'>{$p}</tr>"  : "<tr>{$p}</tr>";
        $s = ($_tierPrices[0]['tier_sale'])? "<tr class='saleRow'>{$s}</tr>"    : '';

        echo "<tbody>$q $p $s</tbody></table>";

    }
?>

FTP_DELETE not working?

Hey guys I have my script here that is supposed to do some stuff then delete a file, unfortunetly my files never unlink. I”m wondering what the reason for this might be? Permissions was the only thing I could think of, or maybe the output buffer is messing up? I really don’t know, but would appreciate some advice on how to handle it. Issue in question is that last IF() block.

public function remoteFtp() {
    $enabled = Mage::getStoreConfig('cataloginventory/settings/use_ftp');
    $remove = Mage::getStoreConfig('cataloginventory/settings/ftp_remove_file');
    if ($enabled == 0) {
        return true;
    }

    $base_path = Mage::getBaseDir('base');


    $ftp_url = Mage::getStoreConfig('cataloginventory/settings/ftp_url');
    $ftp_user = Mage::getStoreConfig('cataloginventory/settings/ftp_user');
    $ftp_pass = Mage::getStoreConfig('cataloginventory/settings/ftp_password');
    $ftp_remote_dir = Mage::getStoreConfig('cataloginventory/settings/ftp_remote_dir');
    $ftp_filename_filter = Mage::getStoreConfig('cataloginventory/settings/ftp_remote_filename');

    $ftp_file = $base_path . '/edi/working/working.edi';

    $handle = fopen($ftp_file, 'w');
    $conn_id = ftp_connect($ftp_url);

    ftp_login($conn_id, $ftp_user, $ftp_pass) or die("unable to login");

    if ($ftp_remote_dir) {
        ftp_chdir($conn_id, $ftp_remote_dir);
    }

    //is there a file
    $remote_list = ftp_nlist($conn_id, ".");

    $exists = count($remote_list);

    if ($exists > 0) {
        $len = strlen($ftp_filename_filter) - 1;


        foreach ($remote_list as $name) {
            if (substr($ftp_filename_filter, 0, 1) == "*") {

                if (substr($name, '-' . $len) == substr($ftp_filename_filter, '-' . $len)) {
                    $ftp_remote_name = $name;
                }
            }
            if (substr($ftp_filename_filter, strlen($name) - 1) == "*") {
                if (substr($ftp_filename_filter, 0, $len) == substr($name, 0, $len)) {
                    $ftp_remote_name = $name;
                }
            }
            if ($ftp_filename_filter == $name) {
                $ftp_remote_name = $name;
            }
        }
    }


    if (ftp_fget($conn_id, $handle, $ftp_remote_name, FTP_ASCII, 0)) {
        echo "successfully written to $ftp_file <br />";
        if ($remove == 1) {
            ftp_delete($conn_id, $ftp_remote_name);
        }
    } else {
        echo "There was a problem while downloading $ftp_remote_name to $ftp_file <br />";
    }

    ftp_close($conn_id);
}

Why is my Call to a Magento Block's getTemplateFile method returning null?

When I use the following code in an index controller

<?php
class Nofrills_Booklayout_IndexController  extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $block = new Mage_Core_Block_Template();        
        $block->setTemplate('helloworld.phtml');
        var_dump($block->getTemplateFile());
    }
}

I expect a result something like this

string 'frontend/base/default/template/helloworld.phtml' (length=47)

However, on my system, I get

null

What’s wrong with my system that it’s returning null for a call to

<code>getTemplateFile</code>

OR how can I debug this myself?

Happening on Magento 1.7.0.1.

Where does Magento Set a Quote Item's Price?

Whenever you load the cart page in Magento, the following code is run

$cart->init();
$cart->save(); 

One side effect of this is that the prices for any items in the cart are updated if the price of the product has been updated. This actually updates the entry in sales_flat_quote_item. I’m trying to track down where in code the price is updated on each quote item, and where each quote item is saved.

I know the myrid locations it could be set. I’m hoping someone knows where it actually is set. Magento 1.7x branch specifically, although info from all versions is welcome.