80 lines
3.0 KiB
PHP
80 lines
3.0 KiB
PHP
<?php
|
|
|
|
use stTaskSchedulerImportProductPeer as GlobalStTaskSchedulerImportProductPeer;
|
|
|
|
/**
|
|
* Subclass for performing query and update operations on the 'st_task_scheduler_import_product' table.
|
|
*
|
|
*
|
|
*
|
|
* @package plugins.stTaskSchedulerImportPlugin.lib.model
|
|
*/
|
|
class stTaskSchedulerImportProductPeer extends BasestTaskSchedulerImportProductPeer
|
|
{
|
|
/**
|
|
* Sprawdza czy produkt jest już powiązany z danym importem
|
|
*
|
|
* @param stTaskSchedulerImportBaseAbstract $import
|
|
* @param Product $product
|
|
* @return bool
|
|
* @throws PropelException
|
|
* @throws SQLException
|
|
*/
|
|
public static function doExist(stTaskSchedulerImportBaseAbstract $import, Product $product)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(self::PRODUCT_ID, $product->getId());
|
|
$c->add(self::IMPORT_HASH_ID, $import->getConfiguration()->getHashId());
|
|
|
|
return self::doCount($c) > 0;
|
|
}
|
|
|
|
public static function doResetProductsAvailability(stTaskSchedulerImportBaseAbstract $import)
|
|
{
|
|
$sel = new Criteria();
|
|
$sel->add(self::IMPORT_HASH_ID, $import->getConfiguration()->getHashId());
|
|
$up = new Criteria();
|
|
$up->add(self::AVAILABLE, false);
|
|
|
|
return BasePeer::doUpdate($sel, $up, Propel::getConnection());
|
|
}
|
|
|
|
public static function doDeactivateNotAvailableProducts(stTaskSchedulerImportBaseAbstract $import)
|
|
{
|
|
$sql = sprintf('UPDATE %s, %s SET %s = %s WHERE %s = %s AND %s = %s AND %s = %d',
|
|
ProductPeer::TABLE_NAME,
|
|
stTaskSchedulerImportProductPeer::TABLE_NAME,
|
|
$import->getConfigurationParameter('withdraw_action', 'withdraw_action') == 'deactivate' ? ProductPeer::ACTIVE : ProductPeer::AVAILABILITY_ID,
|
|
$import->getConfigurationParameter('withdraw_action', 'withdraw_action') == 'deactivate' ? '0' : $import->getConfigurationParameter('withdraw_availability'),
|
|
ProductPeer::ID,
|
|
self::PRODUCT_ID,
|
|
self::IMPORT_HASH_ID,
|
|
$import->getConfiguration()->getHashId(),
|
|
self::AVAILABLE,
|
|
false
|
|
);
|
|
|
|
return Propel::getConnection()->executeUpdate($sql);
|
|
}
|
|
|
|
public static function retrieveByProduct(Product $product, stTaskSchedulerImportBaseAbstract $import): ?stTaskSchedulerImportProduct
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(self::IMPORT_HASH_ID, $import->getConfiguration()->getHashId());
|
|
$c->setLimit(1);
|
|
$results = $product->getstTaskSchedulerImportProducts($c);
|
|
|
|
return !empty($results) ? $results[0] : null;
|
|
}
|
|
|
|
public static function create(Product $product, stTaskSchedulerImportBaseAbstract $import): stTaskSchedulerImportProduct
|
|
{
|
|
$taskSchedulerImportProduct = new stTaskSchedulerImportProduct();
|
|
$taskSchedulerImportProduct->setAvailable(true);
|
|
$taskSchedulerImportProduct->setTaskSchedulerImport($import);
|
|
$product->addstTaskSchedulerImportProduct($taskSchedulerImportProduct);
|
|
|
|
return $taskSchedulerImportProduct;
|
|
}
|
|
}
|