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);

upcell product collection magento

$pid = 2;
$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);

    }
}





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 ();
}

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

));

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]);

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');
}