Jul 252013
 

How to ZIP using SSH

To ZIP a folder via SSH (Secure Shell) log in to your server and at the command line type:

# zip -r myarchive.zip myfolder

This will create a ZIP archive of all files and sub directories

-r (This tells the server to include all files and sub directories)

archive.zip (The name of the zip file you want to create)
myfolder (The folder name you are targetting or use * if you are currently in the folder.)
To UNZIP an archive type:

# unzip myarchive.zip

myarchive.zip (The name of the archive you are extracting)

Aug 222012
 
error_reporting(E_ALL);
ini_set('display_errors', '1');

require_once( 'app/Mage.php');
echo '<pre>';
$app = Mage::app();

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
 
	$readresult = $write->query("SELECT * FROM table limit 1 ");
	$row = $readresult->fetch();
	$SKU = $row['SKU']; 
	if($SKU=='')
	{
		echo 'no Record';
		exit;
	}
	
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$SKU);

echo "Product SKU : ".$SKU."<br>";

if ($product) 
{
	if ($product->getId()) 
	{
		/*$product->setCategoryIds(array(393));
			$product->save();
			exit;*/
		echo "Product ID : ".$product->getId()."<br>";
		echo "Product Name : ".$product->getName()."<br>";
		$categoryIds = $product->getCategoryIds();
		if (is_array($categoryIds) and count($categoryIds) > 0) 
		{
			$theMaster = array();
			print_r($categoryIds);
			$theMaster = array_merge($theMaster,$categoryIds);
			foreach($categoryIds as $curProductCatID  )
			{
				
				echo "Product Category ID : ".$curProductCatID."<br>";
				$theCategory = Mage::getModel('catalog/category')->load($curProductCatID);
			
				if($theCategory->getParentId())
				{
					$cat_array= array($curProductCatID);
					$cat_array = getParentTopCategory($theCategory,$cat_array);
					$final_array= array_reverse($cat_array);
					print_r($final_array);
					$theMaster = array_merge($theMaster,$final_array);
					
				}
				else
				{
					echo 'Parent category  not found<br>';
				}
			}
			echo "master array :";
			print_r($theMaster);
			echo '<br>';
			$tmpA = array();
			
			$theMaster = array_unique ($theMaster);
			foreach($theMaster as $item)
			{
				$tmpA[] = $item;
			}
			echo "master unique array :";
			print_r( $tmpA);
			echo '<br>';
			$product->setCategoryIds($tmpA);
			$product->save();
		}
	}
	else
	{
		echo 'Product not found';
	}
} 

function  getParentTopCategory($category,$cat_array)
{
	echo $category->getName()."<br>";
	if($category->getLevel() == 2)
	{
		$cat_array[]=$category->getParentId();
		return $cat_array;
	}
	else
	{
		
		$parentCategory = Mage::getModel('catalog/category')->load($category->getParentId());
		if($category->getParentId())
		{
			$cat_array[]=$category->getParentId();
			return getParentTopCategory($parentCategory,$cat_array);
		}
		else
		{
			return $cat_array;
		}
	}
}
Aug 212012
 
error_reporting(E_ALL);
ini_set('display_errors', '1');

// Load Up Magento Core
define('MAGENTO', realpath('/'));

require_once(MAGENTO . 'app/Mage.php');

$app = Mage::app();

$categories = Mage::getModel('catalog/category')
 ->getCollection()
 ->addAttributeToSelect('*')
 ->addAttributeToFilter('is_anchor', 0)
 ->addAttributeToFilter('entity_id', array("gt" => 1))
 ->setOrder('entity_id')
 ;

foreach($categories as $category) {
 echo $category->getId() . "\t" . $category->getName() . "\n";
 $category->setIsAnchor(1);
 $category->save();
}
Aug 092012
 

If you want to sent email programmatically.

JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode,
 $cc, $bcc, $attachment, $replyto, $replytoname);

If you need it to be more advanced get mailer and configure on your own

$mailer =& JFactory::getMailer();
$mailer->IsHTML(false);
$mailer->setSubject("Hello World");
$mailer->setBody("Hello from Joomla");
$mailer->addRecipient('your@email.com');
$mailer->AddCustomHeader('X-Header: example');
$mailer->Send();
Aug 072012
 

I have post XML by following code.

    $postdata = http_build_query(
        array( 'xmlInput' => $xml )
    );
    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );
    $context  = stream_context_create($opts);
    $result = file_get_contents($url, false, $context);
Jul 202012
 
require_once 'app/Mage.php';
Mage::app('default'); // Default or your store view name.

//get a new category object
$category = Mage::getModel('catalog/category');
$category->setStoreId(0); // 0 = default/all store view. If you want to save data for a specific store view, replace 0 by Mage::app()->getStore()->getId().

//if update
if ($id) {
  $category->load($id);
}

$general['name'] = "My Category";
$general['path'] = "1/2/23"; // catalog path
$general['description'] = "Great My Category";
$general['meta_title'] = "My Category"; //Page title
$general['meta_keywords'] = "My , Category";
$general['meta_description'] = "Some description to be found by meta search robots. 2";
$general['landing_page'] = ""; //has to be created in advance, here comes id
$general['display_mode'] = "PRODUCTS_AND_PAGE"; //static block and the products are shown on the page
$general['is_active'] = 1;
$general['is_anchor'] = 0;
$general['page_layout'] = 'two_columns_left';

//$general['url_key'] = "cars";//url to be used for this category's page by magento.
//$general['image'] = "cars.jpg";


$category->addData($general);

try {
    $category->save();
    echo "Success! Id: ".$category->getId();
}
catch (Exception $e){
    echo $e->getMessage();
}
Jul 192012
 
$url = 'http://www.personalisedmemento.co.uk/product.php/pid-'.$row['SKU'].'/';

$homepage = file_get_contents($url);
//echo $homepage;

preg_match_all("/<p[^>]*class=\"blackText11\">(.*?)<\\/p>/si", $homepage, $match);
//print_r($match) ;

echo $cate_text = $match[1][1];
echo '<pre>';
preg_match_all('#<a\s+.*?href=[\'"]([^\'"]+)[\'"]\s*(?:title=[\'"]([^\'"]+)[\'"])?.*?>((?:(?!</a>).)*)</a>#i', $cate_text, $match_new);

print_r($match_new) ;

$cat_name = $match_new[3];
$cat_link = $match_new[1];
$cat_string='';
for($i=0;$i<sizeof($cat_link);$i++)
{
	echo $cat_name[$i].'-'.$cat_link[$i];
}
Jun 292012
 
$write = Mage::getSingleton('core/resource')->getConnection('core_write');

$readresult = $write->query("insert into tablename values ('a','b','c')");
// or
$readresult = $write->query("select * from tablename ");

while ($row = $readresult->fetch() ) 
{
	$categoryIds[]=$row['id'];
}