Product Search fixer for when importing products doesn't reindex the search index for them... see http://magento.stackexchange.com/questions/23648/programmatically-trigger-admin-save-action-on-product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* product-search-fixer.php | |
* Forces a product to mimic the admin save in the Magento admin | |
* effectively rebuilding the catalog search index for that product | |
* | |
* @category Mmm | |
* @package ProductSearchFixer | |
* @author Tegan Snyder | |
* | |
*/ | |
require 'app/Mage.php'; | |
Mage::app(); | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$csv = array(); | |
if( ($handle = fopen('skus.csv', "r")) !== FALSE) { | |
$rowCounter = 0; | |
while (($rowData = fgetcsv($handle, 0, ",")) !== FALSE) { | |
if( 0 === $rowCounter) { | |
$headerRecord = $rowData; | |
} else { | |
foreach( $rowData as $key => $value) { | |
$csv[ $rowCounter - 1][ $headerRecord[ $key] ] = $value; | |
} | |
} | |
$rowCounter++; | |
} | |
fclose($handle); | |
} | |
foreach ($csv as $c) { | |
$sku = $c['sku']; | |
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku); | |
echo 'Product: ' . $product->getId() . ' - ' . $product->getName() . PHP_EOL; | |
if (Mage::app()->isSingleStoreMode()) { | |
$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); | |
} | |
$product->save(); | |
} |
Hi,
I got this error
Call to a member function getId() on a non-object on line 34
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi there am i correct in assuming i have to have a csv file called skus.csv with a list of sku's i want this action to be run on?