Bulk Product Updates
php -f nostoProductUpdate.php<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Nosto
* @package Nosto_Tagging
* @author Nosto Solutions Ltd <[email protected]>
* @copyright Copyright (c) 2013-2017 Nosto Solutions Ltd (http://www.nosto.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
require_once 'abstract.php';
class Mage_Shell_Nosto_Product_Update extends Mage_Shell_Abstract
{
const UPDATED_AT = 'updated_at';
const CREATED_AT = 'created_at';
public static $intervalInHrs = 1;
/**
* Get products to be updated
* IMPORTANT! Implement here the logic to only fetch the updated products
*
* @return array
*/
protected function getProducts($start = 1, $limit = 100, DateTimeInterface $updatedAt)
{
$products = Mage::getModel('nosto_tagging/product')->getCollection();
$products->addAttributeToSelect('*')
->addFieldToFilter(
self::UPDATED_AT, array(
'gteq' => $updatedAt->format('Y-m-d H:i:s')
)
)
->setPageSize($limit)
->setCurPage($start)
->setOrder(
self::CREATED_AT,
Varien_Data_Collection::SORT_ORDER_DESC
);
return $products;
}
/**
* Run script
*
*/
public function run()
{
$date = new DateTime('now');
$intervalDefinition = sprintf('PT%dH', self::$intervalInHrs);
$interval = new DateInterval($intervalDefinition);
$date->sub($interval);
$products = $this->getProducts(1, 5, $date);
$productCount = count($products);
if ($productCount > 0) {
printf('Updating %d to Nosto', $productCount);
$service = new Nosto_Tagging_Model_Service_Product();
$service->updateBatch($products);
printf("\n" . 'All done' . "\n");
} else {
printf('Nothing to update');
}
}
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f nostoProductUpdate.php
help This help
USAGE;
}
}
$shell = new Mage_Shell_Nosto_Product_Update();
$shell->run();FAQ
Last updated