Wednesday 18 September 2013

aad to cart product with custom option, super attribute magento

$cartarray = array($textaria_option => $instructions_text,
 $width_option_id => $width,
 $height_option_id => $height,
 $side_optionId => $side_optionVal,
 );
foreach($cartarray as $key=>$val){
if($val!= ''){
$arv[$key] = $val;
}
}

$productIdtoadd=$productDub->getId();
$cart = Mage::getSingelton('checkout/cart');
$cart->addProduct($productIdtoadd, array(
'qty' => $qty,
'total_price'=>$total,
'super_attribute' => array($attributeid =>$assproductColorOptionId),
'options' =>$arv
)
);

Tuesday 17 September 2013

get product custom option magento

$priductid = 82;
$product = Mage::getModel('catalog/product')->load($priductid);

foreach ($product->getOptions() as $o) {
                              $values = $o->getValues();
$optionType = $o->getType();/*********TYPE************/
  $o->getId(); /************getId*****************/

                                     /* dropdown type custom option */
if ($optionType == 'drop_down') {
                                    foreach ($values as $k => $v) {
$drpdoption = $v->getData();
                                    }
                                }
                                       /* end dropdown type custom option */

}

Friday 30 August 2013

save+Edit shipping title+name+Error Message magento

$shipmethods = Mage::getSingleton('shipping/config');

$title = "Aditya_title";
$name = "Aditya_Name";
$Errormessage= "This is shipping error Error Message";


$code = 'shipping_code';


$shipmethods->saveConfig('carriers/'.$code.'/title', "$title", 'stores');
$shipmethods->saveConfig('carriers/'.$code.'/name', "$name", 'stores');
$shipmethods->saveConfig('carriers/'.$code.'/specificerrmsg', "$Errormessage", 'stores');

magento get shipping method


$shippingmethods = Mage::getSingleton('shipping/config');
foreach($shippingmethods as $code =>$carrier){
     $shipTitle = Mage::getStoreConfig('carriers/'.$code.'/title');
     $shipName = Mage::getStoreConfig('carriers/'.$code.'/name');
     $shipErrorMsg = Mage::getStoreConfig('carriers/'.$code.'/specificerrmsg');
}

get data out side of magento

get data out side of magento

include  "app/Mage.php";
Mage::app();


$customModule = Mage::getModel('custommodule/custommodule')->getCollection()->getData();

Saturday 17 August 2013

Magento Add status field in module

open app/code/locel/Package/Module/Block/Adminhtml/Font/Grid.php



$this->addColumn("status", array(
"header" => Mage::helper("Module")->__("status"),
"index" => "status",
"type" => "options",
"options" => Package_Module_Block_Adminhtml_Font_Grid::getValuArray1(),
));


add function getValuArray1 in Grid.php



static public function getValuArray1(){
$data_array1 = Array();
$data_array1[0]='Enabled';
$data_array1[1]='Disabled';
return($data_array1);
}

Tuesday 6 August 2013

magento add event

create new module



add in magento
after that go to app/code/local/package/module/etc/config.xml


find "<frontend>" tag and put the code as given


<events>
            <event>
                <observers>
                    <Package_Module_Model_Observer>
                        <type>singleton</type>
                        <class>Package_Module_Model_Observer</class>
                        <method>Mytestmethod</method>
                    </Package_Module_Model_Observer>
                </observers>
            </event>
        </events>



then go to app/code/local/package/module/model


create a file for event like observer.php
and put the code give for event

some thing like this

<?php
class Package_Module_Model_Observer_Observer {

public function Mytestmethod($observer) {
/*write your here code*/
//$observer->getEvent();
//$event->getProduct();

}
 ?>

Monday 5 August 2013

magento redirect on custom url after login

<?php

if (!Mage::getSingleton("customer/session")->isLoggedIn())
{
$session = Mage::getSingleton("customer/session");

 $session->setBeforeAuthUrl(Mage::helper("core/url")->getCurrentUrl());

$customerLoginURL = $this->getBaseUrl() . "customer/account/login";

Mage::app()->getFrontController()->getResponse()->setRedirect($customerLoginURL)->sendResponse();

 }
 ?>

Friday 14 June 2013

add image in custom module grid magento


create folder on given module path path
code\local\Package\Module\Block\Adminhtml\Module\Renderer

then create file in given folder Image.php

and put the code as suggested.



<?php
class Package_Module_Block_Adminhtml_Module_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   
    public function render(Varien_Object $row)
    {
        $html = '<img width="75" height="75" ';
        $html .= 'id="' . $this->getColumn()->getId() . '" ';
        $html .= 'src="' . Mage::getBaseUrl('media').$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= 'class="grid-image ' . $this->getColumn()->getInlineCss() . '"/>';
      //  $html .= '<br/><p>'.$row->getData($this->getColumn()->getIndex()).'</p>';
        return $html;
    }
}
?>

save file
then go to grid file path is given bellow

app\code\local\Package\Module\Block\Adminhtml\Module\Grid.php

and  add new column in following ways



$this->addColumn('image', array(
'header'    => Mage::helper('module')->__('image'),
'align'     =>'left',
'index'     =>'image',
'renderer' =>'module/adminhtml_module_renderer_image'
));



Tuesday 4 June 2013

get associated product configrable product magento

$productId = 3;
$product = Mage::getModel('catalog/product')->load($productId);
$configrable = $product->getTypeInstance()->getUsedProducts();
foreach($configrable as $config){
                  $config->getId();
                  $config->name;
                  }