Magento arrives with some really good functionality that allows store owners to create automatically generated coupons. Later those coupons can be sent to individual customers in marketing campaigns. Sometimes this strategy will not be insufficient in order to respond to certain business situations because the business case could require that the individual coupons be generated in third party system and later imported in Magento.
This weekend I’ve decided to do some programming for fun. I’ve developed a Magento extension that allows store owners to import coupons in Magento via Advanced Import/Profiles. So far the extension looks more like a proof of concept because it imports coupons that have very simple actions.
The coupons imported by my extension can be used in case you want have coupons for certain SKUs.
I’ve stuck to this basic functionality because describing coupon actions and conditions could lead to complicated data structure and right now I don’t have a clear idea how this data can be neatly described in CSV file. I believe that I would have a chance to develop more a flexible import once I get some feedback from people who’ve tried to utilise my extension.
Continue reading “Free Magento extension for Coupons Import”
Recently I had to implement something really interesting in Magento. My task was to check if coupon could be applied to product before the product is added in cart and coupon is submitted. I started implementing this validation on my own but after some digging in Magento core I found the best solution.
I constructed the snippet below after digging in Magento SalesRule module:
// Sales Rule Id of the coupon we want to validate
$ruleId = 359;
// Id of Product we want to validate
$productId = 884;
/** @var Mage_SalesRule_Model_Rule $salesRule */
$salesRule = Mage::getModel('salesrule/rule')->load($ruleId);
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($productId);
$item = new Varien_Object();
$isValid = (bool) $salesRule->getActions()->validate($item);
var_dump($isValid); // true OR false
Hope this helps!
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 220.127.116.11 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”