This Stack Overflow question is a nice example of how something that seems simple (querying for and updating a widget instance’s data paramaters) can be harder than you think. Most Magento projects go off the rails because someone assumes something like this is easy, and then modern company culture doesn’t allow them to admit it and they’re forced into hastily writing a bunch of inefficient code. Kudos to the asker in that question for backing off their solution.
This is also interesting because the whole “store a serialized object in a column” thing is the opposite of Magento’s older EAV approach.
Filed under php magento widget
Rewriting a resource model in Magento can be tricky business. This Stack Overflow answer covers the how and why.
A Stack Overflow answer where I run through the steps I take to determine if there’s caching logic around the “Custom Variables” feature.
If you’re having trouble with a call like
echo $this->getChildHtml('foo');
returning an empty string, add the following debug code to your template
var_dump(array_keys($this->_children));
This will print out all the children of the current block. If you don’t see the block you’re trying to echo above, that means your block (foo above) isn’t being correctly added to the current block. Check the your custom layout xml for subtle errors (missing name, type, etc.)
Nothing dredges up fear and loathing in an e-commerce developer like the phrase
so we’ll just add [—] to the order success page
That’s because testing any changes to this page requires a full purchase flow. Most web developers work in a “type, save, refresh, examine, oops, type, save, refresh” mode, and the idea of “click, click, fill out form, click, fill out form, click, etc., click, examine, oops — oh crap not again” is anathema.
Whenever I need to make a change to the success page in Magento, I’ll walk through a purchase flow (which will save a last order ID in my session), and then temporarily comment out the following lines in the Checkout controller
#File: app/code/core/Mage/Checkout/controllers/OnepageController.php
public function successAction()
{
$session = $this->getOnepage()->getCheckout();
// if (!$session->getLastSuccessQuoteId()) {
// $this->_redirect('checkout/cart');
// return;
// }
...
}
This lets me realod the success page
http://store.example.com/checkout/onepage/success/
all I want without being redirected, and any required head/keyboard banging may resume as per normal.
I haven’t had time to check it out, but the Sonassi folks have shared their build script for rolling out a new version of Magento. I think we all have something like this sitting on our harddrives, but I know mine is sort of janky so I’ll be checking out the Sonassi version right away.
Apparently Magento blocks have an assign method, which produces behavior more like a “traditional” PHP MVC view layer. I was sort of aware of this, but it never really sunk in until @vinaikopp’s tweet.
That is, if you use code like this
#File: app/code/core/Mage/Review/Block/Product/View.php
...
$this->getLayout()->getBlock('product_review_list.count')
->assign('count', $this->getReviewsCollection()->getSize())
...
then your phtml view file will have access to a local variable named $count.
Probably old hat for most of you, but repeating a lesson never hurts.