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”
Today I worked on task that required the region filed to be removed from all Magento address forms. I found some Magento modules that were doing the trick, but I also wanted to delve a bit more deeper and to see if I can do this by configuration from Magento admin. Luckily in the most recent version of the platform ( Magento CE 1.9 ) this is possible.
By some simple actions in the Magento admin you will be able to exclude the region field from:
- Customer add / edit address form
- Customer register form
- Billing and Shipping address form on the checkout page
Below I am going to show 2 different solutions how to hide the region filed. The first is more suitable for Magento admins / store owners and the second is something that the developers can use in their data upgrade scripts.
For the both example below I assume that we have to remove the region if the country is Germany.
Continue reading “Magento: Remove the region from address form”
Not long ago, my team and I had to change our local Magento development environment to something new and experimental. We changed our local setup so right now we run Magento with docker. So far it’s still experimental and we change the Docker setup quite often. This means that we destroy and recreate the local environment quite often. One of the side effects is that we frequently destroy all sessions, and as a side effect, we get logged out from the Magento admin area a lot.
Furthermore, we are running Magento 188.8.131.52 and this version comes with a built-in protection to save the Magento admin credentials in the browser. Basically, by removing the protection we were able to save the login credentials and to login much faster. I decided to save some clicks and I created a simple Magento extension that automatically logs in developers when they try to reach the admin area. Basically, I wrapped in the extension code for the admin auto login that can be found on the Internet, but I polished the code up a bit and added some configuration settings.
You can download CeckosLab_AutoLogin by cloning it from GitHub or installing it with Modman.
Continue reading “Magento: Admin auto login extension”