Magento is a complex open source eCommerce platform. It’s open source nature and welcoming community means anyone can pick it up, learn it and launch it. After working on over 300 different Magento sites in the past 6 years, however, I’ve learned that many of the misconceptions about Magento - it’s slow, hard to work with, buggy or unstable come from projects that were built by first-timers who weren’t aware of Magento best practices. In this tutorial, I walk you through the entire process of creating, testing and deploying a high-performing, fast Magento-based eCommerce website.
42. getting fancier with your dev environment
frontend: http://127.0.0.1:8080
backend: http://127.0.0.1:8080/admin
User: admin Password: password123123
43. getting fancier with your dev environment
to ssh in: vagrant ssh
to shut down vm: vagrant halt
44. first up - install extensions and theme
install purchased extension
install purchased theme
51. Resolving extension conflicts
easy way - ask extension author for help
or
make one extension dependent on other
or
merge the code into a new extension
52. begin development work
if working with a team, split up the work
easiest split is theme work vs backend work
74. class rewrites
module’s config.xml specifies item to be
overridden
requests to the core class is then rewritten
to your module
75. class rewrites
before every call, magento checks if there is
a rewrite for the class
replaces the core class with your class
76. class rewrites - example
from codegento.com
example - display “loves magento” after the
customer’s name
77. class rewrites - example class
class Super_Awesome_Model_Customer extends Mage_Customer_Model_Customer
{
public function getName()
{
$name = parent::getName();
$name = $name . ' loves Magento';
return $name;
}
}
78. class rewrites - example config.xml
<global>
<models>
<customer>
<rewrite>
<customer>Super_Awesome_Model_Customer</customer>
</rewrite>
</customer>
</models>
</global>
85. events
that was 20 out of over 400 events
find an event that matches your needs
86. observer example
from stackoverflow
Every time someone purchases a product I
need Magento to deduct that quantity from
certain child skus behind the scenes
88. observer example - config.xml, continued
<frontend>
<events>
<checkout_type_onepage_save_order_after>
<observers>
<yourmodule_save_order_observer>
<class>YourCompany_YourModule_Model_Observer</class>
<method>checkout_type_onepage_save_order_after</method>
</yourmodule_save_order_observer>
</observers>
</checkout_type_onepage_save_order_after>
</events>
</frontend>
89. observer example - config.xml, continued
<global>
<models>
<yourmodule>
<class>YourCompany_YourModule_Model</class>
</yourmodule>
</models>
</global>
</config>
90. observer example - class
class YourCompany_YourModule_Model_Observer
{
public function checkout_type_onepage_save_order_after(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getOrder();
/**
* Grab all product ids from the order
*/
$productIds = array();
foreach ($order->getItemsCollection() as $item) {
$productIds[] = $item->getProductId();
}
91. observer example - class, continued
foreach ($productIds as $productId) {
$product = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($productId);
if (! $product->isConfigurable()) {
continue;
}
92. observer example - class, continued
/**
* Grab all of the associated simple products
*/
$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProducts(null, $product);
foreach($childProducts as $childProduct) {
93. observer example - class, continued
/**
* in_array check below, makes sure to exclude the simple product actually
* being sold as we dont want its stock level decreased twice :)
*/
if (! in_array($childProduct->getId(), $productIds)) {
/**
* Finally, load up the stock item and decrease its qty by 1
*/
$stockItem = Mage::getModel('cataloginventory/stock_item')
->loadByProduct($childProduct)
->subtractQty(1)
->save()
94. observer example - class, continued
/**
* Finally, load up the stock item and decrease its qty by 1
*/
$stockItem = Mage::getModel('cataloginventory/stock_item')
->loadByProduct($childProduct)
->subtractQty(1)
->save()
;
}
}
}
}
}
95. events & observers
why doesn’t everyone use them?
lack of knowledge
seeking shortcuts
lack of event matching their needs
107. see my testing talk on thursday
thursday morning, 10AM, this room
108. in the meantime…
github.com/MageTest
watch the magento fireside chats on testing
109. a brief overview of testing magento
a good start:
manual QA review
110. a brief overview of testing magento
even better:
automated Functional testing
111. a brief overview of testing magento
best:
test/behavior driven development
112. conducting manual qa
check the basics - core mods, code smell
complete user acceptance testing
basic regression testing
113. conducting more advanced QA
come to my testing talk on thursday
in the meantime, if you install & use vagrant,
you have behat, behatmage, phpspec,
magespec, phpunit