Created
August 11, 2014 21:18
-
-
Save tegansnyder/2de24f96ab463f074b23 to your computer and use it in GitHub Desktop.
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I got this error
Call to a member function getId() on a non-object on line 34