Thursday, December 1, 2011

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;