Last few weeks I was fighting with problem that partially broke Magento url indexer. Basically the url indexer was working but at certain point it was breaking. At this point I was getting exception and not all url rewrites were written to core_url_rewrite table. Everyday the problem was getting bigger and bigger because all new products contained “catalog/product/view/id” (I call those urls – “ugly” urls) but the desired urls suppose to be human readable and end with “.html”.
This issue could be reproduced only on live environment and in order to reproduce it locally I had to copy all catalog tables (catalog_*) and core_url_rewrite table from live to local environment.
When I run Magento url indexer from command line I got:
php shell/indexer.php --reindex catalog_url
An error occurred while saving the URL rewrite
In Magento exception log I had:
exception 'PDOException' with message 'SQLSTATE:
Integrity constraint violation: 1062 Duplicate entry 'product/2469/361-1-1'
for key 'UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID''
Continue reading “Magento: Url indexer duplicate records problem”
Last few weeks I was searching for solution that allows me to reduce time of Magento database upgrade. In my case I had to upgrade very old Magento version to Magento CE 22.214.171.124 During my tests I found that database upgrade took around 6 hours. The reason was that I had very large database and of course there were a lot of database schema changes (e.g. removing a column of large table was taking ages). This meant that we could have at least 6 hours of down time during upgrade. This was a bit risky because we had limited time span and wanted to go live as soon as possible.
The the good news is that because of my research I managed to reduce database upgrade time from 6 hours to 2 hours! If you are impatient to try the solution just checkout Magento-Upgrade-Replay. I recommend also to read Troubleshooting section of this post.
Continue reading “Faster database upgrade with magento upgrade replay”
Let’s assume that as developer you are in following situation: You know a product id and you have to fetch single attribute value of a product which id you already know. For example let’s try to get color attribute of Magento product.
Question: How would you do it? Are you going to load the product or you would look for more efficient solutions in order to fetch only the attribute you are looking for?
Magento allows us to fetch product attribute in many ways and depending on the context we could choose one. I am definitely against loading entire product in case there are much more efficient solutions and the goal is to fetch single product attribute (not all product attributes).
I think that people choose the easy way because:
- People read the first answer (which sometimes is not the most efficient) in StackOverflow but don’t check other answers.
- There is a lack of Magento documentation.
- Missing out of the box way how to accomplish the task.
- There are many examples in Internet but they are not descriptive enough to explain what happens on background and how efficient they are.
Continue reading “Magento: Load single product attribute vs. load entire product”
Чрез Magento модула ePay Bg имате възможност да приемате плащания от микросметка в ePay Bg, плащане в офиса на EasyPay или банкомат с услугата B-Pay, плащане чрез кредитна карта Борика, Visa, Mastercard и Маестро или, казано по друг начин, услугата „ePay свят“.
За да инсталирате последната версия на модула, моля, използвайте тази връзка – https://github.com/ceckoslab/epaybg/archive/master.zip
Continue reading “Magento модул за разплащания чрез ePay Bg”
About 2 weeks ago I worked on extension for Image Selector in Magento admin forms and I had to use base64 decode and encode functions. Basically Magento backend was sending me base64 encoded string and I had to to use base64 decode function in order to decode the data. I was lucky because Magento Core Team already had implemented such a functionality in JS files and those files were loaded in admin interface.
We have base64 functions in:
- js/mage/adminhtml/tools.js (exists >= Magento CE 1.4 versions)
- js/mage/adminhtml/hash.js (exists in older and current Magento CE versions)
I preferred the implementation in tools.js because it’s more robust when we do some Magento and utf8 specific things and there were functions that helped me to decode base64 strings used in URL.
I developed simple RegEx that allowed me to extract url parameters that are enclosed with slashes. In the example below I am showing how to get parameter “entity_id”:
var url = 'http://example.com/catalog/product/view/entity_id/447/';
var regex = new RegExp('/\\entity_id\/([^\/]+)\/');
var entityId = regex.exec(url); // entityId = 447
Today I will introduce Magento extension that allows developers to create different choosers in Magento admin forms.
List of available choosers:
- Image Chooser
- Product Chooser
- Category Chooser
- CMS Page Chooser
- Static Block Chooser
You can clone or download the extension from here: https://github.com/extendix/Extendix_AdminFormChooserButton
For this extension I used a code base of Magento extension that I created while I was working for Session Digital GmbH. I decided to take control and continue maintenance of the extension from my account and my namespace.
Continue reading “Magento: Extension for creating chooser button in admin form”
Every day I get new ideas but unfortunately there is the time factor and my personal goals that don’t allow me to complete everything I want. At the beginning of this week I got interesting email from Ronald about something that was in my head since I’ve created Magento extension for custom cart validations. So this time I said to myself “Now is the moment!”:
I read your article on custom cart validation in Magento on http://www.sessiondigital.de/blog/magento-create-custom-cart-validation-rules-developers-module/ and I have a question.
I have been breaking my head over a way to enable Magento to sell products in multiples of X, but with any product combination possible. An example would be wine bottles. Any combination of wine bottles is possible, but checkout is only possible if the total quantity is a multiple of 6. If that rule is not validated, a message for the customer is displayed and checkout is disabled.
Would your method be the way to go here, and if so, can you point me in the right direction? Do you have a working example?
Your help is much appreciated.
Continue reading “Magento: Allow checkout if cart quantity multiplies in predefined number”
During last 2 weeks I worked a lot with bundle products. My task was to get the maximal and minimal prices of bundle product. I used those prices in order to create meta data for schema.org – AggregateOffer. I had to find a way how to get the maximal and minimal price of bundle product. Below you will find a snippet that provides a solution. The snippet was taken from “app/design/frontend/base/default/template/bundle/catalog/product/price.phtml” in Magento CE 1.9 .
* @var $_priceModel Mage_Bundle_Model_Product_Price
$_priceModel = $_product->getPriceModel();
list($_minimalPriceTax, $_maximalPriceTax) = $_priceModel->getTotalPrices($_product, null, null, false);
list($_minimalPriceInclTax, $_maximalPriceInclTax) = $_priceModel->getTotalPrices($_product, null, true, false);
// Debug info
Last few weeks me and my team had to install around 10 third party Magento extensions. We have our own local setup and development workflow, but one of the key elements is MODMAN. All extensions (ours and the third party extensions) are linked in Magento by modman. With our current setup and the situation with the number of the new third party extensions we were forced to create modman files for all new extensions. We had to create manually the definitions in the modman files in order to define how the extensions files should be linked in Magento. There was no room for mistakes, but during the process we started experiencing problems, because of the human factor. From time to time we were missing to write modman definitions for some template, layout and css files.
I spotted the need that we need reliable and automated tool, which allows us to create modman files without missing any definitions. At the beginning I was thinking to write my own shell scrip, but as I didn’t want to reinvent the wheel I decided to use my professional network and to ask the Magento community (thanks to one of my first mentors Stefan Stefanov for always reminding me to search for existing concepts / tools / frameworks rather than reinventing the wheel). I asked for help in twitter. The first minute I published my tweet I got answers from Magento community members.
Continue reading “Magento: Generate modman files”