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 184.108.40.206 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”
Today, while I was browsing YouTube, I accidentally stumbled upon a video from April 2012. The video was from a hackathon organised by Osijek Software City and the main character was me. I had completely forgotten about the great time that I had back in 2012 and watching this video again made my day.
Also, I mustn’t forget to say “thanks” to my friends from Inchoo who invited me to attend this event. I remember that the trip from Bulgaria to Osijek was long and I felt very tired, but it was definitely worthy. I met new people at the hackathon and I had some great personal and technical conversations. As a matter of fact, I met my friend Vedran Subotic at this event who, two years after “opened the door” for my moving to München, Germany.
On the hackathon I had to work alone because most of the attendees had teams and the attendees who were alone were too far from my professional expertise. I wanted to do something with Magento but the potential team members were good at C#.
Continue reading “From the archives: Osijek Software City hackathon – April 2012”
Good morning P. and P.
As we we couldn’t catchup yesterday and I couldn’t feed you with proper feedback, then I promised to write you an open letter with all the points that I wanted to discuss.
First of all thanks for the git pull request and giving me the chance to review your code. I have to say that in general I am quite impressed. You managed to “draw the line” where is the scope your work and you properly marked the places inside the templates where the backend team have to step in. The idea with the TODOs and the timestamp was really original. This will make the things for us much more easier in the near future, when we will replace your static texts with our data getters.
There was something specific for your pull request. It contained many commits and it was representing your work from the last weeks. I noticed some small issues that were repeated in different template files.
Continue reading “Open letter to 2 Magento frontend developers”
Recently, a friend developer who is new to Magento asked me: “How can I find all orders that have more than one invoice?”. His company’s accounting department have found that they have more than 1 invoice for some orders, but according to the company’s business rules, they must have exactly 1 invoice per order.
I offered my help and managed to write a very simple query that could help him.
Sql query that list all orders that have more than 1 invoice:
SELECT sales_flat_order.*, COUNT(sales_flat_invoice.order_id)
FROM sales_flat_order, sales_flat_invoice
WHERE sales_flat_order.entity_id = sales_flat_invoice.order_id
GROUP BY sales_flat_invoice.order_id HAVING COUNT(*) > 1;
Hope that this helps somebody else!
Your thoughts / questions?
A couple of months ago I had a really interesting and very importatnt task. I had to code an automated process that creates Unirgy_DropshipPo purchase orders (Unirgy_DropshipPo_Model_Po objects). Because the task had a very high business value and everything had to work flawlessly, I decided to invest more energy and time in order to write a good test coverage with phpunit. I also knew that I needed tests because there was a big chance my code would be modified in the following weeks because of the business dynamics. I decided to “step” on something that I already knew how to utilise – EcomDev_PHPUnit ( Thank you Ivan Chepurnyi ).
Initially, my idea was to use EcomDev_PHPUnit only as a unit-testing tool and to test functions in isolation, but at a later stage of the development I found out that it would be even better if I used EcomDev_PHPUnit to test different branches of my algorithm.
During the development phase I had 3 main technical challenges:
- Unknown / Unexpected behaviour of Unirgy Dropship
- Collecting fixtures data in order to simulate test cases close to production environment
- Querying the database in order to prove that entities have been modified or created (Purchase order, credit memos and etc.)
Continue reading “Magento: Tips and tricks how to test Unirgy Dropship module with EcomDev PHPUnit”
During the last few weeks I’ve been having a lot of fun with my current project. Recently I had to invent SQL queries in order to fetch data from the database. “At the end of the day” I had a nice looking-query but it was really slow. The query was taking around 1.2 sec to execute but it was really simple and had to be executed in a production environment every 30 minutes. By our standards, we couldn’t allow such a slow query on a Magento production shop. In addition, I will say that the query was executed on a table where we had many insert and update queries while the customer was interacting with the Magento frontend.
After a short investigation I found out that adding and index to a column that I was using in the where clause reduced execution time from 1.2 sec to 0.02 sec. The good news was that the table to which I wanted to add the index was part of our own module (not part of a core or community module) and I had the freedom to add this index without doing any “harm”.
Continue reading “Magento: Add column index from upgrade scrip”
This morning I was looking for some new and interesting articles and I found one titled Are You Giving Your Users Positive Feedback? In this article I’ve found one very simple and elegant solution of something that always bothered me while shopping online. As I’m impatient person I always have problems with clicking more than once on the add to cart button and few times I’ve purchased items in bigger quantity that I’ve intended. I’ve never seen a web shop, that offers this simple solution presented in the article I’ve read – adding message for items that are already in the shopping cart.
Continue reading “Magento: Check if product is already in cart”