Problems and Solutions
Catalog Rules are not being applied after night¶
There is a problem where catalog pricing rules are being dropped overnight. Here is the list of people discussing about it.
And the solution is this extension Chuvisco_CatalogRuleFix
Change page title in layout¶
The specific page title can be changed in the page's xml layout.
<reference name="head">
<action method="setTitle">
<title>Insert Your Title Here</title>
</action>
</reference>
Add custom column to customer¶
This goes through the process of adding an IP column to the customer table.
The account controller override can be taken out and it can be replaced by an observer which logs the IP every time the customer logs in,
public function customerLogin($observer)
{
$customer = $observer->getCustomer();
$ip = Mage::app()->getRequest()->getServer('HTTP_X_FORWARDED_FOR');
$customer['customer_ip_address'] = $ip;
$customer->save();
}
Double model rewrite¶
There isn’t an easy way around extension conflicts. You could argue that better programming will work – e.g. by using Observers, taking advantage of source and backend models, writing your own MVC to sit alongside core Magento, etc. But my experience has shown that there are scenarios where you just need a re-write, especially where you are directly manipulating core functionality. Read more
Scenario: Trying to rewrite the Sitemap core magento model while it is already rewritten by another module(let's call it Module A).
Module A config.xml
<!--add comment to point out the rewrite has been modified/moved-->
<global>
<models>
<!--<sitemap>-->
<!--<rewrite>-->
<!--<sitemap>Company_ModuleA_Model_Sitemap</sitemap>-->
<!--</rewrite>-->
<!--</sitemap>-->
</models>
</global>
Add the re-write to your module's config.xml
<global>
<models>
<sitemap>
<rewrite>
<sitemap>EdmondsCommerce_CategorySitemap_Model_Sitemap</sitemap>
</rewrite>
</sitemap>
</models>
</global>
Add the depends tag in your module's xml reg file (eg public/app/etc/modules/EdmondsCommerce_CategorySitemap.xml
)
<config>
<modules>
<EdmondsCommerce_CategorySitemap>
<active>true</active>
<codePool>local</codePool>
<depends>
<Company_ModuleA />
</depends>
</EdmondsCommerce_CategorySitemap>
</modules>
</config>
Create your class EdmondsCommerce_CategorySitemap_Model_Sitemap
that will extend the ModuleA class
class EdmondsCommerce_CategorySitemap_Model_Sitemap extends Company_ModuleA_Model_Sitemap {
//insert override code here
}
How to debug a broken patch¶
- Diagnose the problem
- Google the path common problems
- Get patch file
- Check if all the patch changes/files exist
- Run patch file with -R example:
sh PATCH_SUPEE-10888_CE_v1.9.3.7_v1-2018-09-19-02-59-39.sh -R
- Check if anything fails
- Get missing files until it is not failing
- Run revert patch file again
- Re-apply the patch
- Run
magerun sys:setup:run
- Check scrips versions
magerun sys:setup:compare-versions
- Test site make sure everything is ok
Invalid form key when saving stuff¶
There were two individual issues that were reported. First was that when saving certain cms blocks, magento would not save the changes and throw an "Invalid Form Key" error. The second issues was that when trying to import a price list, magento would say that the file is not uploaded because it is invalid. See screenshots below.
"Invalid form key" error¶
"File was not uploaded" error¶
Beginning of debugging (assuming all steps will fail)¶
- Try to replicate in dev LXC
- Ask the client for more details (in this case, screen recordings were requested)
- Replicate the exact steps as the client in dev LXC
- Get same database as the client (preferably the dev live site and nto the actual live site)
- If the problem can be replicated, then XDebug the code and see where the faulty DB entry is
- If the dev environment is still not replicating the problem, use the dev site
- Find where the actual error is coming from
- Use
var_dump($_POST); die();
before the code throws the error. - Check if the post contains the "form_key" parameter
- In this particular case the post was completely empty on the slightly larger saved CMS blocks.
- This was caused by the server settings that strip post request above a certain threshold.