If you've upgraded or cleared the image caches for magento 2, you may notice that every catalog page loads the images at a snail pace, and if you have any load balancers that restrict php processes (like hypernode does), it may not load more than say 9 images on the page before giving up and showing broken links.
The short version of why this is happening, is because after you clear the cached thumb/small/etc images, you are only left with base images at full size (at least as far as magento is concerned) and so every time it wants to display a smaller image, it has to reprocess it on the fly, this uses php code, and this is why we encounter problems, we're asking too much of magento and a server by using more than our share of php processes to convert every single image on the catalog page.
You can obviously minimise the issue by limiting the items per page to 9 or 12 or whatever, but this is a workaround not a solution.
As it happens, magento has thought about this and provided a function to "pre-warm" the image cache and generate all the necessary images in all sizes.
You should know that a) you need shell access and b) you need a while (on our server, 10k products took about 4 hours).
The function is as follows. You should really only be doing this if you are familiar with the magento binary.
/bin/magento catalog:images:resize
Pretty simple, when you know, and when it works.
Tuesday, 12 November 2019
Thursday, 9 May 2019
Magento 2 - Attention! Something went wrong!
Something went wrong with processing the default view and we have restored the filter to its original state.
So says the product grid in the backend of Magento 2 when you're innocently trying to edit stuff.This is something to do with filtering although I don't entirely (yet) know how to trigger it.
The Fix:
Well, looking around, I found this page on stackexchange which has a couple of solutions, but for me the solution appears (because you never want to fully commit in magento 2!) to solve this.
Go to phpmyadmin, table admin_user, and figure out the user_id of the affected user by just looking at the table. Write that down.
Then go to table ui_bookmark and find the row for any other user_id, copy the contents of key config for namespace product_listing identifier current, into the same field of the affected user_id
Or to try to put it simply, copy across the contents of the config field from one that works for another user.
I feel like you ought to be able to just delete the line for the affected user_id too, as I notice they're not generated for pages you haven't looked at before, so it should regenerate it, but I felt that my way of copying the data would be safer without looking at how the code works.
This field contains a load of information on which fields were last sorted and filtered it seems. Resetting that with good data fixes this, without having to clear any caches or reindex.
Looks harder than it is, trust me.
Oh and don't forget to backup your database first!
Update:
It kept happening. Digging a bit further it seems it's being caused or partly caused by having "sku" to "Null" on some values in the catalog_product_entity table.
props to this site for figuring that out somehow
If you go into phpmyadmin, load up catalog_product_entity, and sort based on sku column, you might (probably will!) see some values of SKU with "Null".
The reason this happened is because in magento 1 at least, if you duplicate a product, it creates a duplicate with blank SKU. If you then save it and don't enter an SKU, or don't save it, I think you get these null sku products.
Hmm.
Magento 2 fun!
Well, I wouldn't really call it fun, honestly.
It's now May 2019, Magento 2 was released, or perhaps we should say it escaped, several years ago, so I thought it must be ready for production, surely.
Well, depends on your opinion I guess.
Anyway - this blog is getting revived - because it needs to be. Here goes.
Woop.
It's now May 2019, Magento 2 was released, or perhaps we should say it escaped, several years ago, so I thought it must be ready for production, surely.
Well, depends on your opinion I guess.
Anyway - this blog is getting revived - because it needs to be. Here goes.
Woop.
Tuesday, 6 August 2013
Editing Magento's Checkout Success Page - A Great Tip (Stop the page from clearing on refresh!)
Here's a great tip I picked up. On checkout completion, the page shows once with "Checkout Success" etc.
However, when you press F5 or refresh, you get dumped to an empty cart and have to go through the whole thing again.
But you can stop this.
Go to:
app\code\core\Mage\Checkout\controllers\OnepageController.php
and comment out line 227:
//$session->clear();
Now, next time you go through checkout, you can refresh the page as much as you like, and get all your CSS layout, xml, etc all sorted in one go.
Fantastic.
Don't forget to change it back though!!
However, when you press F5 or refresh, you get dumped to an empty cart and have to go through the whole thing again.
But you can stop this.
Go to:
app\code\core\Mage\Checkout\controllers\OnepageController.php
and comment out line 227:
//$session->clear();
Now, next time you go through checkout, you can refresh the page as much as you like, and get all your CSS layout, xml, etc all sorted in one go.
Fantastic.
Don't forget to change it back though!!
Tuesday, 11 June 2013
Adding a CMS static block into nearly any page (example: cms block on contact us page)
Easier than it sounds, this. It only works with phtml files, I think.
1) Go to your backend, cms -> static blocks. Create a block with the content you wish to display and the important bit, NOTE the Identifier, that's the key we use to call the block.
In this example I created a block and called it "contactusblock".
2) Open the phtml file, in this case app\design\frontend\<yourname>\default\template\contacts\form.phtml
Add:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('contactusblock')->toHtml() ?>
anywhere you like in the phtml file.
Clear any caches, etc.
Good to go.
1) Go to your backend, cms -> static blocks. Create a block with the content you wish to display and the important bit, NOTE the Identifier, that's the key we use to call the block.
In this example I created a block and called it "contactusblock".
2) Open the phtml file, in this case app\design\frontend\<yourname>\default\template\contacts\form.phtml
Add:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('contactusblock')->toHtml() ?>
anywhere you like in the phtml file.
Clear any caches, etc.
Good to go.
Wednesday, 20 March 2013
Help! My magento checkout button stopped working
This is a short but weird one.
I had a problem where the site worked perfectly up to the checkout button. Which would do nothing. Nothing at all.
After pulling my hair out, I realised the cause.
In the database, in table "core_config_data", the secure website url had a single carriage return after it.
Would have saved me hours of work if someone had posted that online. So here I am, posting it.
Enjoy!
I had a problem where the site worked perfectly up to the checkout button. Which would do nothing. Nothing at all.
After pulling my hair out, I realised the cause.
In the database, in table "core_config_data", the secure website url had a single carriage return after it.
Would have saved me hours of work if someone had posted that online. So here I am, posting it.
Enjoy!
Using magento on a dev or test server, with proper domain names instead of IP addresses. Virtual Host setup guide.
There are times when you need to run magento on a local dev server or WAMP installation or just anywhere, and you don't want an IP address, but instead you want to use a proper domain name.
For example I came across a particularly ridiculous problem with a module's licence; the module would only work on the root domain, and any subdomains of that. For example it worked on www.rubbishmodule.com and shop.rubbishmodule.com but if you moved your site to a dev server, eg 192.168.1.100/rubbishmodule/ it no longer worked.
Something had to be done. And it was easier than I thought. The process is:
1) Set up apache to use "Name based virtual hosting"
2) Edit the necessary files on magento
3) Setup hosts file on pc, or a trick, the router
Apache is a cleverpants. You can use two types of routing to "fake" a web domain on a dev server or any other server running apache. I won't go into it, because you're likely to only ever need Name Based variety.
So - easy peasy. Open up your httpd.conf. On CentOS, it's probably in /etc/httpd/conf/httpd.conf. Remember you need to be superuser or you'll be frustrated when you can't save the file ;)
Scroll to the bottom.
Find and uncomment:
# Use name-based virtual hosting.
NameVirtualHost *.80
Add below somewhere:
<VirtualHost *.80>
DocumentRoot /var/www/html/ <- this is the absolute path to your dev website root
ServerName test.rubbishmodule.com <- this is the web domain you want to "fake"
ErrorLog /var/www/rubbishmodule_error_log <- this can be anywhere
CustomLog /var/www/rubbismodule_access_log <- likewise.
</VirtualHost>
That's that. You can add as many entries as you like, thats how name based works, apache will just route to the right DocumentRoot for the ServerName you've given. Genius.
Oh. You need to restart apache too. Usually
service httpd restart
will do the trick. Google it if you're stuck here.
But it won't work until you do steps 2 and 3...
You need to go into phpmyadmin and browse the core_config_data table. Find the entry for web/unsecure/base_url
It's a big table, but its there.
Change the data to http://test.rubbishmodule.com/
DONT forget the trailing forward slash. If you do, all manner of naughty breaks loose
Now clear /var/cache and /var/session folders in your magento root
Now you need to tell your PC where to find this server. This is by editing your hosts file. Plenty on this if you google it, but the basics are in Windows:
open c:\windows\system32\drivers\etc\hosts
Go to the bottom
Add in
192.168.1.100 test.rubbishmodule.com <- ip of your dev server, your fake domain
Bingo. All works.
Now, as an extra, if you have a dd-wrt router, you can do this on the router, so every PC can see the test site!
For example I came across a particularly ridiculous problem with a module's licence; the module would only work on the root domain, and any subdomains of that. For example it worked on www.rubbishmodule.com and shop.rubbishmodule.com but if you moved your site to a dev server, eg 192.168.1.100/rubbishmodule/ it no longer worked.
Something had to be done. And it was easier than I thought. The process is:
1) Set up apache to use "Name based virtual hosting"
2) Edit the necessary files on magento
3) Setup hosts file on pc, or a trick, the router
1. Apache
Apache is a cleverpants. You can use two types of routing to "fake" a web domain on a dev server or any other server running apache. I won't go into it, because you're likely to only ever need Name Based variety.
So - easy peasy. Open up your httpd.conf. On CentOS, it's probably in /etc/httpd/conf/httpd.conf. Remember you need to be superuser or you'll be frustrated when you can't save the file ;)
Scroll to the bottom.
Find and uncomment:
# Use name-based virtual hosting.
NameVirtualHost *.80
Add below somewhere:
<VirtualHost *.80>
DocumentRoot /var/www/html/ <- this is the absolute path to your dev website root
ServerName test.rubbishmodule.com <- this is the web domain you want to "fake"
ErrorLog /var/www/rubbishmodule_error_log <- this can be anywhere
CustomLog /var/www/rubbismodule_access_log <- likewise.
</VirtualHost>
That's that. You can add as many entries as you like, thats how name based works, apache will just route to the right DocumentRoot for the ServerName you've given. Genius.
Oh. You need to restart apache too. Usually
service httpd restart
will do the trick. Google it if you're stuck here.
But it won't work until you do steps 2 and 3...
2. Magento
You need to go into phpmyadmin and browse the core_config_data table. Find the entry for web/unsecure/base_url
It's a big table, but its there.
Change the data to http://test.rubbishmodule.com/
DONT forget the trailing forward slash. If you do, all manner of naughty breaks loose
Now clear /var/cache and /var/session folders in your magento root
3. Hosts
Now you need to tell your PC where to find this server. This is by editing your hosts file. Plenty on this if you google it, but the basics are in Windows:
open c:\windows\system32\drivers\etc\hosts
Go to the bottom
Add in
192.168.1.100 test.rubbishmodule.com <- ip of your dev server, your fake domain
Bingo. All works.
Now, as an extra, if you have a dd-wrt router, you can do this on the router, so every PC can see the test site!
Go to
Services -> Services -> DNSMasq: http://192.168.1.1/Services.asp
address=/test.rubbishmodule.com/192.168.1.100
Subscribe to:
Posts (Atom)
