Monday, December 26, 2011

Creating a new attribute and adding to attribute set with groups in magento programmatically

Hi,

We can create new attribute and adding to attribute set with particular groups in magento programmatically




$attribute_set_name="Default";  //attribute set name
 $group_name="New Attribute";  //  Inside attribue set you will get groups  ex:- General, prices etc
  //My "simple product only" attribute
createAttribute(strtolower(str_replace(" ", "_", 'Cable Functionality')), "Cable Functionality", "select", "simple",$attribute_set_name,$group_name);

function createAttribute($code, $label, $attribute_type, $product_type, $attribute_set_name, $group_name )
{
    $_attribute_data = array(
        'attribute_code' => $code,
        'is_global' => '1',
        'frontend_input' => $attribute_type, //'boolean',
        'default_value_text' => '',
        'default_value_yesno' => '0',
        'default_value_date' => '',
        'default_value_textarea' => '',
        'is_unique' => '0',
        'is_required' => '0',
        'apply_to' => array($product_type), //array('grouped')
        'is_configurable' => '0',
        'is_searchable' => '0',
        'is_visible_in_advanced_search' => '0',
        'is_comparable' => '0',
        'is_used_for_price_rules' => '0',
        'is_wysiwyg_enabled' => '0',
        'is_html_allowed_on_front' => '1',
        'is_visible_on_front' => '0',
        'used_in_product_listing' => '0',
        'used_for_sort_by' => '0',
        'frontend_label' => array($label)
    );
 
    $model = Mage::getModel('catalog/resource_eav_attribute');
 
    if (!isset($_attribute_data['is_configurable'])) {
        $_attribute_data['is_configurable'] = 0;
    }
    if (!isset($_attribute_data['is_filterable'])) {
        $_attribute_data['is_filterable'] = 0;
    }
    if (!isset($_attribute_data['is_filterable_in_search'])) {
        $_attribute_data['is_filterable_in_search'] = 0;
    }
 
    if (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0) {
        $_attribute_data['backend_type'] = $model->getBackendTypeByInput($_attribute_data['frontend_input']);
    }
 
    $defaultValueField = $model->getDefaultValueByInput($_attribute_data['frontend_input']);
    if ($defaultValueField) {
      //  $_attribute_data['default_value'] = $this->getRequest()->getParam($defaultValueField);
    }
 
    $model->addData($_attribute_data);
 
    $model->setEntityTypeId(Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId());
    $model->setIsUserDefined(1);
    try {
        $model->save();
  $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
   //-------------- add attribute to set and group

   $attribute_code = $code;

            $attribute_set_id=$setup->getAttributeSetId('catalog_product', $attribute_set_name);
            $attribute_group_id=$setup->getAttributeGroupId('catalog_product', $attribute_set_id, $group_name);
            $attribute_id=$setup->getAttributeId('catalog_product', $attribute_code);

            $setup->addAttributeToSet($entityTypeId='catalog_product',$attribute_set_id, $attribute_group_id, $attribute_id);
  
    } catch (Exception $e) { echo '<p>Sorry, error occured while trying to save the attribute. Error: '.$e->getMessage().'</p>'; }
}

Sunday, December 25, 2011

Adding images from third party server or external server to product in magneto programmatically

Hi,

We can add images to product from 3ed party server programmatically in magneto

thing you will have images URL in array



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

$images=array('http://p.imgci.com/db/PICTURES/CMS/140500/140554.icon.jpg','http://p.imgci.com/db/PICTURES/CMS/140500/140553.icon.jpg');
for($j=0;$j<count($images);$j++){
  $image_url  =$images[$j]; //get external image url from csv
    
  $image_url  =str_replace("https://", "http://", $image_url); // repalce https tp http
  //echo $image_url;
  $image_type = substr(strrchr($image_url,"."),1); //find the image extension
  $filename   = $sku.$j.'.'.$image_type; //give a new name, you can modify as per your requirement
  $filepath   = Mage::getBaseDir('media') . DS . 'import'. DS . $filename; //path for temp storage folder: ./media/import/
  file_put_contents($filepath, file_get_contents(trim($image_url))); //store the image from external url to the temp storage folder
  //echo $filepath; exit;

  $filepath_to_image=$filepath;
  $mediaAttribute = array (
    'thumbnail',
    'small_image',
    'image'
  );
 $product->addImageToMediaGallery($filepath_to_image, $mediaAttribute, true, false);

   }

Friday, December 23, 2011

Adding product from fornt-end with image in mangento programmatically

Hi,

We can add a product from frond end in magneto Paste this code in file and place the file in root folder of project run this file in browser product will created and also give image correct path the image also uploaded




<?php
 define('MAGENTO', realpath(dirname(__FILE__)));
 require_once MAGENTO . '/app/Mage.php';
 Mage::app();
 $storename='default';
 
  

//$product = Mage::getModel('catalog/product');
$product = new Mage_Catalog_Model_Product();
echo time();
// Build the product
$product->setAttributeSetId(4);// #4 is for default
$product->setTypeId('simple');

$product->setName('Some cool product name');
$product->setDescription('Full description here');
$product->setShortDescription('Short description here');
$product->setSku(time());
$product->setWeight(4.0000);
$product->setStatus(1);
$filepath_to_image='image.jpg';
$mediaAttribute = array (
                'thumbnail',
                'small_image',
                'image'
        );
$product->addImageToMediaGallery($filepath_to_image, $mediaAttribute, true, false);
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);//4
print_r(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);

$product->setPrice(39.99);// # Set some price
$product->setTaxClassId(0);// # default tax class

$product->setStockData(array(
'is_in_stock' => 1,
'qty' => 99999
));

$product->setCategoryIds(array(27));// # some cat id's,

$product->setWebsiteIDs(array(1));// # Website id, 1 is default

//Default Magento attribute

$product->setCreatedAt(strtotime('now'));


//print_r($product);
try {
    $product->save();
    echo "Product Created";
}
catch (Exception $ex) {
    //Handle the error
    echo "Product Creation Failed";
}

?>

Tuesday, December 20, 2011

Applying Custom discount amount in magento

Hi,

In few case you have to write a code so that custom discount as to apply to cart

either you can ave discount amount in Db or static i am showing the cod for static one

in your custom module etc/config.xml add this code in side global tag
<?xml version="1.0"?>
<config>
    <modules>
        <Sugarcode_Customdiscount>
            <version>1.0.10</version>
        </Sugarcode_Customdiscount>
    </modules>
    
    
    <global>
 
        <events>
        <!-- Création éventuelle du lien de parrainage lors de la commande -->
            <sales_quote_collect_totals_after>
                <observers>
                    <set_custom_discount_suagrcode>
                        <type>singleton</type>
                        <class>Sugarcode_Customdiscount_Model_Observer</class>
                        <method>setDiscount</method>
                    </set_custom_discount_suagrcode>
                </observers>
            </sales_quote_collect_totals_after>             
   
  </events>
        
    </global>

   
</config>

and inside model folder create file called Observer.php
(if only custom discount)

 <?php
/**
 * @category   Sugarcode
 * @package    Sugarcode_Customdiscount
 * @author     pradeep.kumarrcs67@gmail.com
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Sugarcode_Customdiscount_Model_Observer
{

    
 public function setDiscount($observer)
    {
       $quote=$observer->getEvent()->getQuote();
       $quoteid=$quote->getId();
       $discountAmount=10;
    if($quoteid) {
       
       
      
        if($discountAmount>0) {
  $total=$quote->getBaseSubtotal();
   $quote->setSubtotal(0);
   $quote->setBaseSubtotal(0);

   $quote->setSubtotalWithDiscount(0);
   $quote->setBaseSubtotalWithDiscount(0);

   $quote->setGrandTotal(0);
   $quote->setBaseGrandTotal(0);
  
    
   $canAddItems = $quote->isVirtual()? ('billing') : ('shipping'); 
   foreach ($quote->getAllAddresses() as $address) {
    
   $address->setSubtotal(0);
            $address->setBaseSubtotal(0);

            $address->setGrandTotal(0);
            $address->setBaseGrandTotal(0);

            $address->collectTotals();

            $quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
            $quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());

            $quote->setSubtotalWithDiscount(
                (float) $quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount()
            );
            $quote->setBaseSubtotalWithDiscount(
                (float) $quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount()
            );

            $quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
            $quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
 
   $quote ->save(); 
 
      $quote->setGrandTotal($quote->getBaseSubtotal()-$discountAmount)
      ->setBaseGrandTotal($quote->getBaseSubtotal()-$discountAmount)
      ->setSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
      ->setBaseSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
      ->save(); 
      
    
    if($address->getAddressType()==$canAddItems) {
    //echo $address->setDiscountAmount; exit;
     $address->setSubtotalWithDiscount((float) $address->getSubtotalWithDiscount()-$discountAmount);
     $address->setGrandTotal((float) $address->getGrandTotal()-$discountAmount);
     $address->setBaseSubtotalWithDiscount((float) $address->getBaseSubtotalWithDiscount()-$discountAmount);
     $address->setBaseGrandTotal((float) $address->getBaseGrandTotal()-$discountAmount);
     if($address->getDiscountDescription()){
     $address->setDiscountAmount(-($address->getDiscountAmount()-$discountAmount));
     $address->setDiscountDescription($address->getDiscountDescription().', Custom Discount');
     $address->setBaseDiscountAmount(-($address->getBaseDiscountAmount()-$discountAmount));
     }else {
     $address->setDiscountAmount(-($discountAmount));
     $address->setDiscountDescription('Custom Discount');
     $address->setBaseDiscountAmount(-($discountAmount));
     }
     $address->save();
    }//end: if
   } //end: foreach
   //echo $quote->getGrandTotal();
  
  foreach($quote->getAllItems() as $item){
                 //We apply discount amount based on the ratio between the GrandTotal and the RowTotal
                 $rat=$item->getPriceInclTax()/$total;
                 $ratdisc=$discountAmount*$rat;
                 $item->setDiscountAmount(($item->getDiscountAmount()+$ratdisc) * $item->getQty());
                 $item->setBaseDiscountAmount(($item->getBaseDiscountAmount()+$ratdisc) * $item->getQty())->save();
                
               }
            
                
            }
            
    }
 }

} 

Monday, December 12, 2011

Redirecting the page In magento

If your are redirect in controller page use this code






 $this->_redirect('checkout/cart/');




id your redirecting other the controller like model, etc use this code




Mage::app()->getResponse()->setRedirect(Mage::getUrl("checkout/cart/"));

Friday, December 2, 2011

Avoid fraud from editing payment method through fire bug to free in magneto

Hi,

Today i come across one fraud in magneto checkout page

some user can edit payment method to free payment through fire bug and if submit order it will submit and place order

we can avoid this thing

just edit code or extend this model in your local folder in Mage_Sales_Model_Service_Quote i’e

app\code\core\Mage\Sales\Model\Service\Quote.php

in function _validate() add this code (around 293 )






//pradeep to avoid foud from select free in fire bug
            $qu=Mage::getModel('sales/quote')->load($this->getQuote()->getId());
            if($qu->getPayment()->getMethod()=='free' && $qu->getGrandTotal()!=0){
                Mage::throwException($helper->__('Invalid payment method'));
            }




so it will avoid placing order even if the subtotal is not zero in magneto

Thursday, December 1, 2011

Sending email with attachment in magento programmatically

Hi,

we can send custom email with attachment in magneto

i am sending email acc to date of orders. this email contain 2 csv file of both pending and invoiced orders

create a email template system->Transactional Emails

i’e


Template Name :-  Daily Order Reports
Template Subject :- {{var subject}}

Template Content
Hi
<p>
Please check attached csv  file  of  {{var subject}}
</p> 



save it u will get email Template id once u save this email

create one file in root folder of project paste this below code and save it


<?php
 define('MAGENTO', realpath(dirname(__FILE__)));
 require_once MAGENTO . '/../app/Mage.php';
 Mage::app();
 $storename='default';
 $string="sku,alu,name,qty,mrp,sold price,size,color,final price\n"; 
 function add_dateAction($givendate,$day=0,$mth=0,$yr=0,$hr=0,$min=0,$sec=0) {
  $cd = strtotime($givendate);
  $newdate = date('Y-m-d H:i:s', mktime(0+$hr,
     0+$min, 0+$sec, date('m',$cd)+$mth,
     date('d',$cd)+$day, date('Y',$cd)+$yr));
  return $newdate;
 }

  $from=add_dateAction(now(),-1,0,0);
  $report_date=date("d_M_y", mktime(0, 0, 0, date("m"),date("d")-1,date("Y")));
  echo 'Report On '.$report_date.'<br />';
  $to= add_dateAction(now(),-1,0,0,23,59,59);
  $orderCollection = Mage::getResourceModel('sales/order_collection');
  $orderCollection->addFieldToFilter('status', array('eq'=>'pending'))->addAttributeToSelect('entity_id');
  $orderCollection->getSelect()  
      ->where("main_table.created_at BETWEEN '".$from."' AND '".$to."'");
   // $orderCollection->printlogquery(true); exit;
  $i=0;
  foreach($orderCollection->getItems() as $order){
            $orderModel = Mage::getModel('sales/order');
            $orderModel->load($order['entity_id']);
   $i++;
         //echo $orderModel->getIncrementId().', '.$orderModel->getPayment()->getMethod().'<br />';
 
    foreach ($orderModel->getAllItems() as $_product) {
    $_loadedprod=Mage::getModel('catalog/product')->load($_product->getData('product_id'));
   $size=Mage::getModel('catalog/product')
                            ->load($_loadedprod->getId())
                            ->getAttributeText('size');
   $color=Mage::getModel('catalog/product')
                            ->load($_loadedprod->getId())
                            ->getAttributeText('color');
  
    $string .= $_product->getSku() . ',' .$_loadedprod->getData('alu') . ',' . $_product->getData('name') . ',' .$_product->getData('qty_ordered').  ',' .$_product->getData('orginal_mrp').  ',' .$_product->getData('original_price'). ',' .$size . ',' .$color . ',' .$_product->getData('base_row_total_incl_tax') . "\n";
        
            }
   
   
 
        }
  echo 'Total Pending orders:-'.$i.'<br />';
  
  //Invoice Order Report
  
  
 $string2="sku,alu,name,qty,mrp,sold price,size,color,final price\n";
   $orderCollection = Mage::getResourceModel('sales/order_invoice_collection')->addAttributeToSelect('entity_id');
  //$orderCollection->addFieldToFilter('status', array('eq'=>'pending'));
  $orderCollection->getSelect()       
      ->where("main_table.created_at BETWEEN '".$from."' AND '".$to."'");
   // $orderCollection->printlogquery(true); exit;
  $i=0;
  foreach($orderCollection->getItems() as $order){
 
            
   $i++;
         //echo $orderModel->getIncrementId().', '.$orderModel->getPayment()->getMethod().'<br />';
 
    foreach ($order->getAllItems() as $_product) {
   $orderitem=Mage::getModel('sales/order_item')->load($_product->getData('order_item_id'));
  
    $_loadedprod=Mage::getModel('catalog/product')->load($_product->getData('product_id'));
   $size=Mage::getModel('catalog/product')
                            ->load($_loadedprod->getId())
                            ->getAttributeText('size');
   $color=Mage::getModel('catalog/product')
                            ->load($_loadedprod->getId())
                            ->getAttributeText('color');
    $string2 .= $_product->getSku() . ',' .$_loadedprod->getData('alu') . ',' . $_product->getData('name') . ',' .$_product->getQty().  ',' .$orderitem->getOrginalMrp().  ',' .$_product->getPrice(). ',' .$size . ',' .$color . ',' .$_product->getData('base_row_total_incl_tax') . "\n";
        
            }
   
   
 
        }
  
 
  echo 'Total inviced orders:-'.$i.'<br />';
  
  
  
  
  $templateId =6;
   // Set sender information
  $senderName = 'report '; // Mage::getStoreConfig('trans_email/ident_support/name');
  $senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
  //$size = $this->getRequest()->getParam('size');
  $sender = array('name' => $senderName,
                'email' => $senderEmail);
 
  // Set recepient information
  $recepientEmail = 'youremail@doine.com'; //Mage::getStoreConfig('trans_email/ident_support/email'); //email from support admin side
  $recepientName =    'pradeep';     
 
  // Get Store ID
  $store = Mage::app()->getStore()->getId();
 
  // Set variables that can be used in email template
  $vars = array('subject' =>  'Daily Order Report 0n '.date("M d Y", mktime(0, 0, 0, date("m"),date("d")-1,date("Y"))));
  
  $translate  = Mage::getSingleton('core/translate');
  $transactionalEmail = Mage::getModel('core/email_template')->setDesignConfig(array('area'=>'frontend', 'store'=>1));
  $transactionalEmail->getMail()->createAttachment($string,'text/UTF-8')->filename = 'pending_orders_'.$report_date.'.csv';
  $transactionalEmail->getMail()->createAttachment($string2,'text/UTF-8')->filename = 'invoiced_orders_'.$report_date.'.csv';
  if($transactionalEmail->sendTransactional($templateId, $sender, $recepientEmail, "Admin", $vars)) {
   echo 'mail sent';
  //$this->getResponse()->setRedirect($url);
  }else{
          echo 'mail not sent';
        }
  
?>

Creating xml file of all products fields in magento programmatically

Hi,

below code is used to create a xml file of all product for some 3ed party site
place this code in magento project root folder






<?php
 define('MAGENTO', realpath(dirname(__FILE__)));
 require_once MAGENTO . '/app/Mage.php';
 Mage::app();
 $storename='default';
 $file = "products_xml.xml";
if (file_exists($file)) { unlink ($file); }
 
?>


    <?php


$products = Mage::getModel('catalog/product')
   ->getCollection()
   ->addAttributeToSelect('*')
   ->addAttributeToFilter('status', array('eq' => '1'))
   ->addAttributeToFilter('type_id', array('eq' => 'simple'));

//process your product collection as per your bussiness logic


  $doc = new DOMDocument();
  $doc->formatOutput = true;
  
  $productsX = $doc->createElement( "products" );
  $doc->appendChild( $productsX );
  
foreach($products as $_product){
//print_r($_product->getData()); exit;
 /*echo $_product->getSku().'</br>';
 echo $_product->getName().'</br>';
 echo $_product->getData('image').'</br>';
 echo $_product->getData('small_image').'</br>';
 echo $_product->getData('thumbnail').'</br>'; 
 echo $_product->getData("url_key").'</br>';
 echo $_product->getShippingDelivery().'</br>';
 echo $_product->getShippingWeight() .'</br>';
 echo $_product->getAlu().'</br>'; 
 echo $_product->getUpsize().'</br>';
 echo $_product->getPrice().'</br>';
 echo $_product->getSpecialPrice().'</br>'; 
 echo $_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product).'</br>'; 
 echo $_product->getResource()->getAttribute('status')->getFrontend()->getValue($_product).'</br>'; 
 echo $_product->getResource()->getAttribute('gender')->getFrontend()->getValue($_product).'</br>'; 
 echo $_product->getResource()->getAttribute('size')->getFrontend()->getValue($_product).'</br>';
 echo $_product->getResource()->getAttribute('season')->getFrontend()->getValue($_product).'</br>';
 echo $_product->getDescription().'</br>';
 echo Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty().'</br>'; 
 echo Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock().'</br>';
 exit; */
 $product = $doc->createElement( "product" );
  
 $sku = $doc->createElement( "sku" );
 $sku->appendChild(
  $doc->createTextNode($_product->getSku())
 );
 $product->appendChild( $sku );
  
 $name = $doc->createElement( "name" );
 $name->appendChild(
  $doc->createTextNode( trim($_product->getName()) )
 );
 $product->appendChild( $name );
  
 $image = $doc->createElement( "image" );
 $image->appendChild(
  $doc->createTextNode( trim($_product->getData('image')) )
 );
 $product->appendChild( $image );
  
 $smallimage = $doc->createElement( "smallimage" );
 $smallimage->appendChild(
  $doc->createTextNode( trim($_product->getData('small_image')) )
 );
 $product->appendChild( $smallimage );
  
 $thumbnail = $doc->createElement( "thumbnail" );
 $thumbnail->appendChild(
  $doc->createTextNode( trim($_product->getData('thumbnail')) )
 );
 $product->appendChild( $thumbnail );
  
 $urlkey = $doc->createElement( "urlkey" );
 $urlkey->appendChild(
  $doc->createTextNode( trim($_product->getData('url_key')) )
 );
 $product->appendChild( $urlkey );
  
 $shippingdelivery = $doc->createElement( "shippingdelivery" );
 $shippingdelivery->appendChild(
  $doc->createTextNode( trim($_product->getShippingDelivery()) )
 );
 $product->appendChild( $shippingdelivery );
  
 $shippingweight = $doc->createElement( "shippingweight" );
 $shippingweight->appendChild(
  $doc->createTextNode( trim($_product->getShippingWeight()) )
 );
 $product->appendChild( $shippingweight );
  
 $alu = $doc->createElement( "alu" );
 $alu->appendChild(
  $doc->createTextNode( trim($_product->getAlu()) )
 );
 $product->appendChild( $alu );
  
 $upsize = $doc->createElement( "upsize" );
 $upsize->appendChild(
  $doc->createTextNode( trim($_product->getUpsize()) )
 );
 $product->appendChild( $upsize );
  
 $price = $doc->createElement( "price" );
 $price->appendChild(
  $doc->createTextNode( trim($_product->getPrice()) )
 );
 $product->appendChild( $price );
  
 $specialprice = $doc->createElement( "specialprice" );
 $specialprice->appendChild(
  $doc->createTextNode( trim($_product->getSpecialPrice()) )
 );
 $product->appendChild( $specialprice );
  
 $color = $doc->createElement( "color" );
 $color->appendChild(
  $doc->createTextNode( trim($_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product)))
 );
 $product->appendChild( $color );
  
 $status = $doc->createElement( "status" );
 $status->appendChild(
  $doc->createTextNode( trim($_product->getResource()->getAttribute('status')->getFrontend()->getValue($_product)) )
 );
 $product->appendChild( $status );
  
 $gender = $doc->createElement( "gender" );
 $gender->appendChild(
  $doc->createTextNode( trim($_product->getResource()->getAttribute('gender')->getFrontend()->getValue($_product)) )
 );
 $product->appendChild( $gender );
  
 $size = $doc->createElement( "size" );
 $size->appendChild(
  $doc->createTextNode( trim($_product->getResource()->getAttribute('size')->getFrontend()->getValue($_product)) )
 );
 $product->appendChild( $size );
  
 $season = $doc->createElement( "season" );
 $season->appendChild(
  $doc->createTextNode( trim($_product->getResource()->getAttribute('season')->getFrontend()->getValue($_product)) )
 );
 $product->appendChild( $season );
  
 $description = $doc->createElement( "description" );
 $description->appendChild(
  $doc->createTextNode( trim($_product->getDescription()) )
 );
 $product->appendChild( $description );
  
 $qty = $doc->createElement( "qty" );
 $qty->appendChild(
  $doc->createTextNode( trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()) )
 );
 $product->appendChild( $qty );
  
 $availability = $doc->createElement( "availability" );
 $availability->appendChild(
  $doc->createTextNode( trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock()) )
 );
 $product->appendChild( $availability );

   $productsX->appendChild($product);  
    }
  //echo $doc->saveXML();
 file_put_contents($file,$doc->saveXML(),FILE_APPEND);
     ?>


you can check this post http://www.magentocommerce.com/boards/viewthread/267477/

Getting product Qty or quantity in magneto






<?php Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()) ?>

<?php Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock() ?>


Wednesday, November 30, 2011

How to display html code or tag in blogspot.com

use this link you can convert your html code to code which support blogspot post editor

http://francois.schnell.free.fr/tools/BloggerPaste/BloggerPaste.html

Wednesday, October 5, 2011

Giving hypering link for ceratin palce or perticular place in a full image or IMG Tag

Hi,

We can give hyper link to selected place from a image


<div class="slide" style="position: absolute; top: 0px; left: 990px; z-index: 0; display: block;"><img width="990" height="330" alt="" src="img1.png?1317798487966" usemap="#Map">
<map name="Map" id="Map">
<area target="_blank" href="giftcards.html" coords="961,299,840,262" shape="rect">
</map>
</div><div class="slide" style="position: absolute; top: 0px; left: 990px; z-index: 0; display: block;"><img width="990" height="330" alt="" src="img2.png" usemap="#Map2">
<map name="Map2" id="Map2">
<area target="_blank" href="ff.html" coords="1081,305,180,265" shape="rect">
</map>
</div>

Tuesday, September 13, 2011

Getting or Displaying Attributes value and label of product in magento programmatically


//value or label which you select in back end
echo $_product->getResource()->getAttribute('size')->getFrontend()->getValue($_product);

//label of the attribute
echo $_product->getResource()->getAttribute('size')->getFrontend()->getLabel();


// value or option Id
echo $_product->getSize()

Sunday, September 4, 2011

Sending email from local system in magneto OR Sending email from magento in local system

Hi

we can enable sending email from local system if you working magento in local system

we can send or enable sending email from magento in local system

1) make sure you did setting in php.ini

i'e

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.yourdomine.com
; http://php.net/smtp-port
smtp_port = 25

and in magento go to admin

System->Configuration->System->Mail Sending Setting->host

replace host from localhost to mail.yourdomine.com

Tuesday, January 25, 2011

How to remove A,H2 tag color border in google chrome browser

If your getting a border for A,H2 etc.. tag use this one line css code

outline: none;