I want to create a collection of all the products without a image and set them do the status "disabled".
Because i use a automatic import script there are some products that HAD images before, but don't have them anymore.
For that reason, there are images selected, but they don't exist anymore and the placeholder is shown on the frontend.
Is there anyway to still get the collection so i can give those product a new status?
This is what is tried and didn't work:
$_products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(array(
array (
'attribute' => 'image',
'like' => 'no_selection'
),
array (
'attribute' => 'image',
'null' => true
),
array (
'attribute' => 'image',
'eq' => ''
),
array (
'nlike' => '%/%/%'
),
));
Strange thing is that the image is empty (but selected) and still doesn't show up in the collection.
EDIT:
When doing a var_dump on a product that shows a placeholder on the frontend and has no images in the backend i still see the file URL to the non-existing images:
["media_gallery"]=>
array(2) {
["images"]=>
array(3) {
[0]=>
array(9) {
["value_id"]=>
string(5) "49038"
["file"]=>
string(19) "/E/2/E23812_1_1.jpg"
["product_id"]=>
string(4) "4386"
["label"]=>
string(0) ""
["position"]=>
string(2) "13"
["disabled"]=>
string(1) "0"
["label_default"]=>
NULL
["position_default"]=>
string(2) "13"
["disabled_default"]=>
string(1) "0"
}
[1]=>
array(9) {
["value_id"]=>
string(5) "49039"
["file"]=>
string(19) "/E/2/E23812_2_1.jpg"
["product_id"]=>
string(4) "4386"
["label"]=>
string(0) ""
["position"]=>
string(2) "14"
["disabled"]=>
string(1) "0"
["label_default"]=>
NULL
["position_default"]=>
string(2) "14"
["disabled_default"]=>
string(1) "0"
}
[2]=>
array(9) {
["value_id"]=>
string(5) "49040"
["file"]=>
string(17) "/E/2/E23812_3.jpg"
["product_id"]=>
string(4) "4386"
["label"]=>
string(0) ""
["position"]=>
string(2) "15"
["disabled"]=>
string(1) "0"
["label_default"]=>
NULL
["position_default"]=>
string(2) "15"
["disabled_default"]=>
string(1) "0"
}
}
So is there a way to filter a collection for a image URL that links to a non-existing item?
EDIT:
Got it:
$_products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('image');
foreach($_products as $_product){
clearstatcache();
$file = '../media/catalog/product'.$_product->getImage();
if(!file_exists($file)) {
$_product->setStatus(2);
$_product->save();
}
}
Thanks for the help, hope anybody else finds this post useful.