Mar 28, 2017

Magento 2 Getter and Setter Generator

Magento 2 is going away from magic methods and many of Magento 2 classes have getters and setters in their classes.

However, it's time consuming to create these all all your properties on your CRUD Model, so this is why I've created a small tool that generates the getters and setters.


Generate getters and setters

Add your attribute in snake case, comma-seperated in the above input field.




    /**
    * @param $attributeId
    * @return $this
    */
    public function setAttributeId($attributeId)
    {
        return $this->setData('attribute_id', $attributeId);
    }

    /**
    * @param $colorKey
    * @return $this
    */
    public function setColorKey($colorKey)
    {
        return $this->setData('color_key', $colorKey);
    }

    /**
    * @return mixed
    */
    public function getAttributeId()
    {
        return $this->getData('attribute_id');
    }

    /**
    * @return mixed
    */
    public function getColorKey()
    {
        return $this->getData('color_key');
    }

Jun 12, 2013

SVN Merge: List Unmerged Revision Command

One disadvantage of RabbitVCS as compared to TortoiseSVN is that with RabbitVCS you cannot see which revisions have been and have not been merged.

A nice command that I found that can do the job is:

svn mergeinfo ^/calc/branches/development  --show-revs eligible

It will just list the revisions that are not merged yet. It is a nice command that you can use in case you want to merge a branch to trunk for example.

Apr 24, 2013

MSc and BSc Projects


I've decided to open source my academic projects which I've done at BSc and MSc levels, which you can find below.

MSc: Internet Technology and Web Development

My MSc project was titled "Context-Aware Searching for Mobile Devices" and it is about finding affinities between users on Facebook and afterwards suggest products that might interest one user depending on his close friends products usage.

The Document: http://goo.gl/TC8W0
FacebookApp: https://apps.facebook.com/spotfinder/
Code for App: https://github.com/kervin/spotfinder
Android App: https://github.com/kervin/myspotfinder


BSc: Computer Science and Engineering

My BSc Project, which I co-authored, was titled "Suspend Behavior Recognition" and it is a program that, using a webcam, monitors activities at ATMs to sound an Alarm in case there is a suspension of theft or vandalism.

The Document: http://goo.gl/cpm3J


You can also find my CV online: http://goo.gl/jgZX9

Nov 12, 2012

Fuel Consumption Conversion for Mauritius

Fuel Consumption Conversion for Mauritius

Nov 9, 2012

Building Attribute Group Tree


Each product has a defined attribute set in Magento and which is set on creation of the product. Attribute sets consists of a number of attribute groups which in turn has a number of attributes.

Normally that is used only in admin, but I got a request to classify the attributes like that in a grid on frontend, which was a bit tricky. Below is the solution that I came up to.


$retValue = array();

/* @var $product Mage_Catalog_Model_Product  */
$product = Mage::getModel('catalog/product')->load(3224);

// Get the attribute set of the product
$attributeSetId = $product->getAttributeSetId();

// Get the attribute groups associated to the attribute set
$attributeGroups = Mage::getResourceModel('eav/entity_attribute_group_collection')
    ->setAttributeSetFilter($attributeSetId)
    ->load();


// Get the attributes of each group
foreach ($attributeGroups as $value) {
    $group['title'] = $value->getAttributeGroupName();

    $attributes = $product->getAttributes($value->getId());

    $attributeVal = array();

    foreach ($attributes as $attribute) {
        $att['title'] = $attribute->getFrontEndLabel();
        $attributeCode = $attribute->getAttributeCode();

        
        $data = $product->getData($attributeCode);
        if (!empty($data['values'])) {
            $attributeVal = $product->getAttributeText($attributeCode);
        }

        if (!empty($attributeVal)) {
            $att['value'] = $attributeVal;
            $group['value'][] = $att;
        }
    }

        $retValue[] = $group;
}

echo '<pre>';
var_dump($retValue);
echo '</pre>';

Oct 5, 2012

How magento widget form container instantiates a form

In admin for Magento, widget forms are used in order to edit entities. You need a Mage_Adminhtml_Block_Widget_Form_Container that contains a Mage_Adminhtml_Block_Widget_Form (with tabs etc..). The full explanation of how the full edit works is beyond this blog post, and I am concentrating on an issue that I came on.

So, while creating a form, I got the following error:
Fatal error: Call to a member function setData() on a non-object in app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php on line 129 

It took me some time to figure out what going on, and after some digging in mage widget forms, I understood the error. In fact, Magento is not finding the form associated to the form container.

Basically for container to locate the form, it needs 3 attributes, an example below:

    protected $_blockGroup = 'training_commenteav';
    protected $_controller = 'adminhtml_eav_comment';
    protected $_mode = 'edit';

These specify the location of the form. In the parent class, here what's happening:
$this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form')

So for my example it would be "training_commenteav/adminhtml_eav_comment_edit_form" that it will use to create a block instance.

I don't know why you can't just specify the uri of the form as I would have expected. Instead it uses blockgroup, controller and mode. Maybe you could have an abstract class for several modes and reuse the blockgroup and controller which I don't think is that useful. Anyway that is how Magento works with widget forms.


Apr 24, 2012

Magento Country Codes per Continent for Table Rate


I was trying to setup flat shipping rate per continent on Magento and figured out that was not possible.  So I made a little sql script to categorize the countries according to their continent.


If you want more information about how to use it, read that blog post: http://php.quicoto.com/magento-country-codes-for-table-rate/

The information is stored in a database, so if you need if in a different format or with other data, let me know.


Find below the list.

id,code,name,continent

78,GA,Gabon,AFRICA
180,RW,Rwanda,AFRICA
58,CI,"Côte d’Ivoire",AFRICA
206,SD,Sudan,AFRICA
209,SZ,Swaziland,AFRICA
51,CD,"Congo - Kinshasa",AFRICA
50,CG,"Congo - Brazzaville",AFRICA
49,KM,Comoros,AFRICA
43,TD,Chad,AFRICA
42,CF,"Central African Republic",AFRICA
40,CV,"Cape Verde",AFRICA
38,CM,Cameroon,AFRICA
113,KE,Kenya,AFRICA
36,BI,Burundi,AFRICA
60,DJ,Djibouti,AFRICA
216,TZ,Tanzania,AFRICA
79,GM,Gambia,AFRICA
82,GH,Ghana,AFRICA
195,SL,"Sierra Leone",AFRICA
194,SC,Seychelles,AFRICA
192,SN,Senegal,AFRICA
200,SO,Somalia,AFRICA
69,ET,Ethiopia,AFRICA
67,ER,Eritrea,AFRICA
66,GQ,"Equatorial Guinea",AFRICA
201,ZA,"South Africa",AFRICA
64,EG,Egypt,AFRICA
91,GN,Guinea,AFRICA
92,GW,Guinea-Bissau,AFRICA
35,BF,"Burkina Faso",AFRICA
223,TN,Tunisia,AFRICA
157,NE,Niger,AFRICA
129,MW,Malawi,AFRICA
158,NG,Nigeria,AFRICA
136,MR,Mauritania,AFRICA
132,ML,Mali,AFRICA
137,MU,Mauritius,AFRICA
138,YT,Mayotte,AFRICA
146,MA,Morocco,AFRICA
147,MZ,Mozambique,AFRICA
149,NA,Namibia,AFRICA
219,TG,Togo,AFRICA
244,ZM,Zambia,AFRICA
6,AO,Angola,AFRICA
245,ZW,Zimbabwe,AFRICA
3,DZ,Algeria,AFRICA
23,BJ,Benin,AFRICA
230,UG,Uganda,AFRICA
121,LR,Liberia,AFRICA
28,BW,Botswana,AFRICA
128,MG,Madagascar,AFRICA
120,LS,Lesotho,AFRICA
122,LY,Libya,AFRICA


115,KW,Kuwait,ASIA
112,KZ,Kazakhstan,ASIA
151,NP,Nepal,ASIA
1,AF,Afghanistan,ASIA
116,KG,Kyrgyzstan,ASIA
165,PK,Pakistan,ASIA
196,SG,Singapore,ASIA
119,LB,Lebanon,ASIA
164,OM,Oman,ASIA
103,IQ,Iraq,ASIA
143,MN,Mongolia,ASIA
179,RU,Russia,ASIA
106,IL,Israel,ASIA
130,MY,Malaysia,ASIA
102,IR,Iran,ASIA
109,JP,Japan,ASIA
101,ID,Indonesia,ASIA
177,QA,Qatar,ASIA
100,IN,India,ASIA
97,HK,"Hong Kong SAR China",ASIA
172,PH,Philippines,ASIA
131,MV,Maldives,ASIA
117,LA,Laos,ASIA
111,JO,Jordan,ASIA
191,SA,"Saudi Arabia",ASIA
45,CN,China,ASIA
232,AE,"United Arab Emirates",ASIA
25,BT,Bhutan,ASIA
205,LK,"Sri Lanka",ASIA
225,TM,Turkmenistan,ASIA
33,BN,Brunei,ASIA
37,KH,Cambodia,ASIA
217,TH,Thailand,ASIA
215,TJ,Tajikistan,ASIA
212,SY,Syria,ASIA
214,TW,Taiwan,ASIA
18,BD,Bangladesh,ASIA
203,KR,"South Korea",ASIA
224,TR,Turkey,ASIA
17,BH,Bahrain,ASIA
243,YE,Yemen,ASIA
240,VN,Vietnam,ASIA
236,UZ,Uzbekistan,ASIA


134,MH,"Marshall Islands",AUSTRALIA
150,NR,Nauru,AUSTRALIA
237,VU,Vanuatu,AUSTRALIA
114,KI,Kiribati,AUSTRALIA
13,AU,Australia,AUSTRALIA
221,TO,Tonga,AUSTRALIA
166,PW,Palau,AUSTRALIA
140,FM,Micronesia,AUSTRALIA
227,TV,Tuvalu,AUSTRALIA
169,PG,"Papua New Guinea",AUSTRALIA
155,NZ,"New Zealand",AUSTRALIA
189,WS,Samoa,AUSTRALIA
199,SB,"Solomon Islands",AUSTRALIA
72,FJ,Fiji,AUSTRALIA


14,AT,Austria,EUROPE
73,FI,Finland,EUROPE
142,MC,Monaco,EUROPE
141,MD,Moldova,EUROPE
80,GE,Georgia,EUROPE
193,RS,Serbia,EUROPE
15,AZ,Azerbaijan,EUROPE
71,FO,"Faroe Islands",EUROPE
190,SM,"San Marino",EUROPE
144,ME,Montenegro,EUROPE
84,GR,Greece,EUROPE
2,AL,Albania,EUROPE
163,NO,Norway,EUROPE
197,SK,Slovakia,EUROPE
5,AD,Andorra,EUROPE
198,SI,Slovenia,EUROPE
152,NL,Netherlands,EUROPE
81,DE,Germany,EUROPE
74,FR,France,EUROPE
68,EE,Estonia,EUROPE
11,AM,Armenia,EUROPE
133,MT,Malta,EUROPE
204,ES,Spain,EUROPE
98,HU,Hungary,EUROPE
118,LV,Latvia,EUROPE
99,IS,Iceland,EUROPE
56,CY,Cyprus,EUROPE
34,BG,Bulgaria,EUROPE
54,HR,Croatia,EUROPE
210,SE,Sweden,EUROPE
20,BY,Belarus,EUROPE
211,CH,Switzerland,EUROPE
104,IE,Ireland,EUROPE
107,IT,Italy,EUROPE
57,CZ,"Czech Republic",EUROPE
178,RO,Romania,EUROPE
233,GB,"United Kingdom",EUROPE
21,BE,Belgium,EUROPE
231,UA,Ukraine,EUROPE
127,MK,Macedonia,EUROPE
174,PL,Poland,EUROPE
125,LU,Luxembourg,EUROPE
175,PT,Portugal,EUROPE
123,LI,Liechtenstein,EUROPE
124,LT,Lithuania,EUROPE
59,DK,Denmark,EUROPE


234,US,"United States",NAMERICA
168,PA,Panama,NAMERICA
62,DO,"Dominican Republic",NAMERICA
94,HT,Haiti,NAMERICA
108,JM,Jamaica,NAMERICA
96,HN,Honduras,NAMERICA
61,DM,Dominica,NAMERICA
39,CA,Canada,NAMERICA
89,GT,Guatemala,NAMERICA
86,GD,Grenada,NAMERICA
53,CR,"Costa Rica",NAMERICA
55,CU,Cuba,NAMERICA
22,BZ,Belize,NAMERICA
19,BB,Barbados,NAMERICA
65,SV,"El Salvador",NAMERICA
139,MX,Mexico,NAMERICA
16,BS,Bahamas,NAMERICA
156,NI,Nicaragua,NAMERICA

41,KY,"Cayman Islands",OTHERS
186,MF,"Saint Martin",OTHERS
213,ST,"São Tomé and Príncipe",OTHERS
47,CC,"Cocos [Keeling] Islands",OTHERS
52,CK,"Cook Islands",OTHERS
242,EH,"Western Sahara",OTHERS
8,AQ,Antarctica,OTHERS
241,WF,"Wallis and Futuna",OTHERS
7,AI,Anguilla,OTHERS
31,IO,"British Indian Ocean Territory",OTHERS
46,CX,"Christmas Island",OTHERS
218,TL,Timor-Leste,OTHERS
4,AS,"American Samoa",OTHERS
24,BM,Bermuda,OTHERS
229,VI,"U.S. Virgin Islands",OTHERS
228,UM,"U.S. Minor Outlying Islands",OTHERS
27,BA,"Bosnia and Herzegovina",OTHERS
226,TC,"Turks and Caicos Islands",OTHERS
12,AW,Aruba,OTHERS
29,BV,"Bouvet Island",OTHERS
238,VA,"Vatican City",OTHERS
246,AX,"Åland Islands",OTHERS
9,AG,"Antigua and Barbuda",OTHERS
222,TT,"Trinidad and Tobago",OTHERS
32,VG,"British Virgin Islands",OTHERS
220,TK,Tokelau,OTHERS
208,SJ,"Svalbard and Jan Mayen",OTHERS
202,GS,"South Georgia and the South Sandwich Islands",OTHERS
159,NU,Niue,OTHERS
182,BL,"Saint Barthélemy",OTHERS
105,IM,"Isle of Man",OTHERS
110,JE,Jersey,OTHERS
176,PR,"Puerto Rico",OTHERS
126,MO,"Macau SAR China",OTHERS
173,PN,"Pitcairn Islands",OTHERS
135,MQ,Martinique,OTHERS
181,RE,Réunion,OTHERS
145,MS,Montserrat,OTHERS
167,PS,"Palestinian Territories",OTHERS
148,MM,"Myanmar [Burma]",OTHERS
153,AN,"Netherlands Antilles",OTHERS
154,NC,"New Caledonia",OTHERS
162,MP,"Northern Mariana Islands",OTHERS
161,KP,"North Korea",OTHERS
160,NF,"Norfolk Island",OTHERS
183,SH,"Saint Helena",OTHERS
184,KN,"Saint Kitts and Nevis",OTHERS
185,LC,"Saint Lucia",OTHERS
85,GL,Greenland,OTHERS
88,GU,Guam,OTHERS
83,GI,Gibraltar,OTHERS
90,GG,Guernsey,OTHERS
77,TF,"French Southern Territories",OTHERS
76,PF,"French Polynesia",OTHERS
75,GF,"French Guiana",OTHERS
188,VC,"Saint Vincent and the Grenadines",OTHERS
187,PM,"Saint Pierre and Miquelon",OTHERS
70,FK,"Falkland Islands",OTHERS
95,HM,"Heard Island and McDonald Islands",OTHERS
87,GP,Guadeloupe,OTHERS

207,SR,Suriname,SAMERICA
239,VE,Venezuela,SAMERICA
10,AR,Argentina,SAMERICA
235,UY,Uruguay,SAMERICA
48,CO,Colombia,SAMERICA
171,PE,Peru,SAMERICA
26,BO,Bolivia,SAMERICA
63,EC,Ecuador,SAMERICA
44,CL,Chile,SAMERICA
93,GY,Guyana,SAMERICA
170,PY,Paraguay,SAMERICA
30,BR,Brazil,SAMERICA