$this->getLayout()->getBlock('head')->setTitle($this->__('pagetitle'));
Tuesday, 3 June 2014
Sunday, 18 May 2014
magento basics concept
Magento built in zend framework on object orient concept in MVC architecture Based on EDA(Event Driven Architecture).
Whent an event happens element listen event and sent to event engine.
Whent an event happens element listen event and sent to event engine.
Thursday, 6 March 2014
Index management magento programmatically
get All Index process collection
$allIndex= Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach ($allIndex as $index) {
if ($index->getStatus() == Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX) {
$index->reindexEverything();
//echo "<pre>"; print_r($index->getProcess_id()); echo "</pre>";
}
}
Tuesday, 10 December 2013
get payment method in cart magento
for handling payment method display in cart we use event handling we use config.xml in module or in custom module
app/code/local/regitration/field/etc/config.xml
<?xml version="1.0"?>
<config>
<frontend>
<events>
<payment_method_is_active>
<observers>
<Regitration_Field_Model_observer>
<class>Regitration_Field_Model_observer</class>
<method>payment_method_is_active</method>
</Regitration_Field_Model_observer>
</observers>
</payment_method_is_active>
</events>
</frontend>
</config>
define action in observer file
app/code/local/regitration/field/model/observer.php
<?php
class Regitration_Field_Model_observer {
public function payment_method_is_active($observer){
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$session = Mage::getSingleton('checkout/session')->getQuote();
$shippiingcarriers = $session->getShippingAddress()->getShippingMethod();
if ($shippiingcarriers == 'flatrate_flatrate' ){
if($method->getCode() == 'cashondelivery' OR $method->getCode() == 'checkmo' OR $method->getCode() == 'paypal_standard' or $method->getCode()=='purchaseorder'){
$result->isAvailable = false;
}else{
$result->isAvailable = true;
}
}
}
}
?>
app/code/local/regitration/field/etc/config.xml
<?xml version="1.0"?>
<config>
<frontend>
<events>
<payment_method_is_active>
<observers>
<Regitration_Field_Model_observer>
<class>Regitration_Field_Model_observer</class>
<method>payment_method_is_active</method>
</Regitration_Field_Model_observer>
</observers>
</payment_method_is_active>
</events>
</frontend>
</config>
define action in observer file
app/code/local/regitration/field/model/observer.php
<?php
class Regitration_Field_Model_observer {
public function payment_method_is_active($observer){
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$session = Mage::getSingleton('checkout/session')->getQuote();
$shippiingcarriers = $session->getShippingAddress()->getShippingMethod();
if ($shippiingcarriers == 'flatrate_flatrate' ){
if($method->getCode() == 'cashondelivery' OR $method->getCode() == 'checkmo' OR $method->getCode() == 'paypal_standard' or $method->getCode()=='purchaseorder'){
$result->isAvailable = false;
}else{
$result->isAvailable = true;
}
}
}
}
?>
Wednesday, 27 November 2013
get cross cell product collection magento
$cart = Mage::getModel('checkout/cart')->getQuote();
$productid = array();
$crossc = array();
foreach ($cart->getAllItems() as $item) {
$productid[] = $item->getProduct()->getId();
foreach($item->getProduct()->getCrossSellProducts() as $crosscell){
$crossc[] = $crosscell['entity_id'];
}
}
$crossce = array_diff($crossc, $productid);
$collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
$collection->addIdFilter($crossce);
$collection->setPageSize(4);
$productid = array();
$crossc = array();
foreach ($cart->getAllItems() as $item) {
$productid[] = $item->getProduct()->getId();
foreach($item->getProduct()->getCrossSellProducts() as $crosscell){
$crossc[] = $crosscell['entity_id'];
}
}
$crossce = array_diff($crossc, $productid);
$collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
$collection->addIdFilter($crossce);
$collection->setPageSize(4);
upcell product collection magento
$pid = 2;
$product = Mage::getModel('catalog/product')->load($pid);
$collect = $this->getProduct()->getUpSellProductCollection();
$collect->getItems();
$product = Mage::getModel('catalog/product')->load($pid);
$collect = $this->getProduct()->getUpSellProductCollection();
$collect->getItems();
Friday, 1 November 2013
custom price in cart Magento
Add event in module etc/config.xml
<?xml version="1.0"?>
<config>
</frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<Custom_Event_Model_Observer>
<type>singleton</type>
<class>Custom_Event_Model_Observer</class>
<method>Mytestmethod</method>
</Custom_Event_Model_Observer>
</observers>
</checkout_cart_product_add_after>
</events>
</frontend>
</config>
calculate your price in Custom/Event/Model/Observer.php
class Custom_Event_Model_Observer {
public function Mytestmethod(Varien_Event_Observer $observer) {
$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$price = 66;
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);
}
}
<?xml version="1.0"?>
<config>
</frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<Custom_Event_Model_Observer>
<type>singleton</type>
<class>Custom_Event_Model_Observer</class>
<method>Mytestmethod</method>
</Custom_Event_Model_Observer>
</observers>
</checkout_cart_product_add_after>
</events>
</frontend>
</config>
calculate your price in Custom/Event/Model/Observer.php
class Custom_Event_Model_Observer {
public function Mytestmethod(Varien_Event_Observer $observer) {
$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$price = 66;
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);
}
}
Thursday, 24 October 2013
Remove product image magento
$_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load(2);
$removes[0] = a/b/aaa.png;
$removes[1] = a/c/bbb.png;
if(count($remove)>0){
$attributes = $_product->getTypeInstance ()->getSetAttributes ();
$gallery = $attributes ['media_gallery'];
$galleryData = $_product->getMediaGallery();
foreach($removes as $remove) {
foreach($galleryData['images'] as $image) {
if($remove==$image['file']){
$gallery->getBackend ()->removeImage( $_product, $image ['file'] );
}
}
}
$_product->save ();
}
$removes[0] = a/b/aaa.png;
$removes[1] = a/c/bbb.png;
if(count($remove)>0){
$attributes = $_product->getTypeInstance ()->getSetAttributes ();
$gallery = $attributes ['media_gallery'];
$galleryData = $_product->getMediaGallery();
foreach($removes as $remove) {
foreach($galleryData['images'] as $image) {
if($remove==$image['file']){
$gallery->getBackend ()->removeImage( $_product, $image ['file'] );
}
}
}
$_product->save ();
}
Tuesday, 8 October 2013
multi select in custom module magento
$tool_cat_Arr = array(array('value' => '1', 'label' => 'Shirt'), array('value' => '2', 'label' => 'Tshirt'), array('value' => '3', 'label' => 'Custom'));
$fieldset->addField("tool_cat", "multiselect", array(
"label" => Mage::helper("storeinfo")->__("Tool Category"),
"name" => "tool_cat",
"values" => $tool_cat_Arr
));
$fieldset->addField("tool_cat", "multiselect", array(
"label" => Mage::helper("storeinfo")->__("Tool Category"),
"name" => "tool_cat",
"values" => $tool_cat_Arr
));
filter in custom module magento
$stored = 25;
$storeinfo = Mage::getModel("storeinfo/storeinfo")->getCollection()->addFilter('storeowner_id',$stored)->load();
$storeinfoid = $storeinfo->getAllIds();
$Storeinfomodel = Mage::getModel("storeinfo/storeinfo")->load($storeinfoid[0]);
$storeinfo = Mage::getModel("storeinfo/storeinfo")->getCollection()->addFilter('storeowner_id',$stored)->load();
$storeinfoid = $storeinfo->getAllIds();
$Storeinfomodel = Mage::getModel("storeinfo/storeinfo")->load($storeinfoid[0]);
Subscribe to:
Posts (Atom)