Category Archives: PHP

Find Products with No Images

You can find the collection for below code.

$_products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(array(
array (
'attribute' => 'image',
'like' => 'no_selection'
),
array (
'attribute' => 'image', // null fields
'null' => true
),
array (
'attribute' => 'image', // empty, but not null
'eq' => ''
),
array (
'attribute' => 'image', // check for information that doesn't conform to Magento's formatting
'nlike' => '%/%/%'
),
));

you can got all product list which has no Images assign.

Advertisements
PDO-Database-connections-and-abstraction

How to convert a CSV file to an associated array?

Here is a quick and easy way to convert a CSV file to an associated array:

function csv_to_array($filename='', $delimiter=',')
{
	if(!file_exists($filename) || !is_readable($filename))
		return FALSE;

	$header = NULL;
	$data = array();
	if (($handle = fopen($filename, 'r')) !== FALSE)
	{
		while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
		{
			if(!$header)
				$header = $row;
			else
				$data[] = array_combine($header, $row);
		}
		fclose($handle);
	}
	return $data;
}
/**
 * Example
 */

print_r(csv_to_array('phpsolutions.csv',";"));

?>

Example

"id";"name"
1;"keyul Shah"
2;"kushal"

Result

Array
(
    [0] => Array
        (
            [id] => 1
            [name] => keyul Shah
        )

    [1] => Array
        (
            [id] => 2
            [name] => kushal
        )
)

Magento – How to Check if the SKU is Exist?

Hello Friends today I will share with you In Magento – How to Check if the SKU is Exist?

$sku = 'Your Product Sku';
$id = Mage::getModel('catalog/product')->getIdBySku($sku);
if ($id){
    echo "SKU {$sku} exists";
}
else{
    echo "SKU {$sku} does not exist";
}

Where this code will useful.

  • When you import magento products via code then this code is very useful.
  • If you want to load product via sku then this is very useful.
  • if you want to update any particular product  via code then also this is useful.