285 lines
9.2 KiB
PHP
285 lines
9.2 KiB
PHP
<?php
|
|
/**
|
|
* SOTESHOP/stCeneoPlugin
|
|
*
|
|
* Ten plik należy do aplikacji stCeneoPlugin opartej na licencji (Professional License SOTE).
|
|
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
|
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
|
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
|
*
|
|
* @package stCeneoPlugin
|
|
* @subpackage actions
|
|
* @copyright SOTE (www.sote.pl)
|
|
* @license http://www.sote.pl/license/sote (Professional License SOTE)
|
|
* @version $Id: actions.class.php 16435 2011-12-12 08:34:51Z michal $
|
|
* @author Michal Prochowski <michal.prochowski@sote.pl>
|
|
*/
|
|
|
|
/**
|
|
* Klasa stCeneoBackendActions
|
|
*
|
|
* @package stCeneoPlugin
|
|
* @subpackage actions
|
|
*/
|
|
class stCeneoBackendActions extends autostCeneoBackendActions
|
|
{
|
|
/**
|
|
* Walidacja akcji Config
|
|
*/
|
|
public function validateConfig()
|
|
{
|
|
$error = false;
|
|
$request = $this->getRequest();
|
|
|
|
$data = $request->getParameter('config');
|
|
|
|
if (isset($data['trusted_opinion_on']) && $data['trusted_opinion_on'] == 1)
|
|
{
|
|
if (isset($data['trusted_opinion_id']) && empty($data['trusted_opinion_id']))
|
|
{
|
|
$request->setError('config{trusted_opinion_id}', 'Proszę uzupełnić pole.');
|
|
$error = true;
|
|
}
|
|
}
|
|
|
|
if ($error == true)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Przeciążenie aktualizacji config'a
|
|
*/
|
|
protected function updateConfigFromRequest()
|
|
{
|
|
$config = $this->getRequestParameter('config');
|
|
foreach (stCeneo::getAvailabilities() as $availability)
|
|
{
|
|
$this->config->set('availability_'.$availability->getId(), $config['availability_'.$availability->getId()]);
|
|
}
|
|
|
|
if (is_dir(sfConfig::get('sf_plugins_dir')."/appAdsTrackerPlugin")) {
|
|
|
|
if ($config['ads_tracker']==1) {
|
|
appAdsTracker::checkCompare("ceneo",1);
|
|
} else {
|
|
appAdsTracker::checkCompare("ceneo",0);
|
|
}
|
|
}
|
|
|
|
|
|
parent::updateConfigFromRequest();
|
|
|
|
$this->dispatcher->notify(new sfEvent($this, 'stCeneoBackendActions.updateConfigFromRequest'), array('config' => $this->config));
|
|
}
|
|
|
|
|
|
public function executeProductEnable()
|
|
{
|
|
$config = stConfig::getInstance(sfContext::getInstance(), 'stCeneoBackend');
|
|
|
|
$ids = $this->getRequestParameter('ceneo[selected]', array());
|
|
|
|
foreach ($ids as $id) {
|
|
$c = new Criteria();
|
|
$c->add(CeneoPeer::ID, $id);
|
|
$Ceneo = CeneoPeer::doSelectOne($c);
|
|
|
|
if (null === $Ceneo) {
|
|
$Ceneo = new Ceneo();
|
|
$Ceneo->setProductId($id);
|
|
}
|
|
|
|
if ($config->get('buy_now')==1) {
|
|
$Ceneo->setIsBasket(true);
|
|
}
|
|
|
|
$Ceneo->setActive(true);
|
|
$Ceneo->save();
|
|
}
|
|
|
|
return $this->redirect('stCeneoBackend/list?page=' . $this->getRequestParameter('page', 1));
|
|
}
|
|
|
|
public function executeProductDisable()
|
|
{
|
|
$ids = $this->getRequestParameter('ceneo[selected]', array());
|
|
|
|
$con = Propel::getConnection();
|
|
$sel = new Criteria();
|
|
$sel->add(CeneoPeer::ID, array_values($ids), Criteria::IN);
|
|
$up = new Criteria();
|
|
$up->add(CeneoPeer::ACTIVE, false);
|
|
|
|
BasePeer::doUpdate($sel, $up, $con);
|
|
|
|
return $this->redirect('stCeneoBackend/list?page=' . $this->getRequestParameter('page', 1));
|
|
}
|
|
|
|
protected function addFiltersCriteria($c)
|
|
{
|
|
if (isset($this->filters['code_is_empty'])) {
|
|
$criterion = $c->getNewCriterion(ProductPeer::CODE, '');
|
|
$criterion->addOr($c->getNewCriterion(ProductPeer::CODE, null, Criteria::ISNULL));
|
|
$c->add($criterion);
|
|
} else if (isset($this->filters['code']) && $this->filters['code'] !== '') {
|
|
if (method_exists($this, 'filterCriteriaByProductCode')) {
|
|
$filter_anyway = !$this->filterCriteriaByProductCode($c, $this->filters['code']);
|
|
} else {
|
|
$filter_anyway = true;
|
|
}
|
|
|
|
if ($filter_anyway) {
|
|
$c->add(ProductPeer::CODE, '%' . $this->filters['code'] . '%', Criteria::LIKE);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($this->filters['product_is_empty'])) {
|
|
$criterion = $c->getNewCriterion(ProductPeer::OPT_NAME, '');
|
|
$criterion->addOr($c->getNewCriterion(ProductPeer::OPT_NAME, null, Criteria::ISNULL));
|
|
$c->add($criterion);
|
|
} else if (isset($this->filters['product']) && $this->filters['product'] !== '') {
|
|
if (method_exists($this, 'filterCriteriaByProductOptName')) {
|
|
$filter_anyway = !$this->filterCriteriaByProductOptName($c, $this->filters['product']);
|
|
} else {
|
|
$filter_anyway = true;
|
|
}
|
|
|
|
if ($filter_anyway) {
|
|
$c->add(ProductPeer::OPT_NAME, '%' . $this->filters['product'] . '%', Criteria::LIKE);
|
|
}
|
|
}
|
|
if (isset($this->filters['active_is_empty'])) {
|
|
$criterion = $c->getNewCriterion(CeneoPeer::ACTIVE, '');
|
|
$criterion->addOr($c->getNewCriterion(CeneoPeer::ACTIVE, null, Criteria::ISNULL));
|
|
$c->add($criterion);
|
|
} else if (isset($this->filters['active']) && $this->filters['active'] !== '') {
|
|
if ($this->filters['active'] == null || $this->filters['active'] == 0) {
|
|
$criterion = $c->getNewCriterion(CeneoPeer::ACTIVE, '');
|
|
$criterion->addOr($c->getNewCriterion(CeneoPeer::ACTIVE, null, Criteria::ISNULL));
|
|
$c->add($criterion);
|
|
}
|
|
|
|
if ($this->filters['active'] == 1) {
|
|
$c->add(CeneoPeer::ACTIVE, $this->filters['active']);
|
|
}
|
|
}
|
|
|
|
|
|
if ($this->filters) {
|
|
$c->add(CeneoPeer::PRODUCT_ID, 0, Criteria::NOT_EQUAL);
|
|
}
|
|
|
|
if (isset($this->filters['is_basket']) && $this->filters['is_basket'] !== '') {
|
|
|
|
if($this->filters['is_basket']){
|
|
$c->add(CeneoPeer::IS_BASKET, $this->filters['is_basket']);
|
|
}
|
|
else
|
|
{
|
|
$criterion = $c->getNewCriterion(CeneoPeer::IS_BASKET, 0);
|
|
$criterion->addOr($c->getNewCriterion(CeneoPeer::IS_BASKET, null, Criteria::ISNULL));
|
|
$c->add($criterion);
|
|
}
|
|
}
|
|
|
|
$this->getDispatcher()->notify(new sfEvent($this, 'autoStCeneoBackendActions.addFiltersCriteria', array('criteria' => $c)));
|
|
}
|
|
|
|
public function executeAddAll()
|
|
{
|
|
|
|
$config = stConfig::getInstance(sfContext::getInstance(), 'stCeneoBackend');
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
$query = sprintf(
|
|
'INSERT INTO %s(%s, %s) (SELECT %s, 1 FROM %s LEFT JOIN %s AS assigned ON (%s = %s) WHERE %s IS NULL)',
|
|
CeneoPeer::TABLE_NAME,
|
|
CeneoPeer::PRODUCT_ID,
|
|
CeneoPeer::ACTIVE,
|
|
ProductPeer::ID,
|
|
ProductPeer::TABLE_NAME,
|
|
CeneoPeer::TABLE_NAME,
|
|
CeneoPeer::alias('assigned', CeneoPeer::PRODUCT_ID),
|
|
ProductPeer::ID,
|
|
CeneoPeer::alias('assigned', CeneoPeer::PRODUCT_ID)
|
|
);
|
|
|
|
$con->executeQuery($query);
|
|
|
|
$sel = new Criteria();
|
|
$sel->add(CeneoPeer::ACTIVE, false);
|
|
$up = new Criteria();
|
|
$up->add(CeneoPeer::ACTIVE, true);
|
|
|
|
BasePeer::doUpdate($sel, $up, $con);
|
|
|
|
|
|
if ($config->get('buy_now') == 1) {
|
|
|
|
$sel = new Criteria();
|
|
$sel->add(CeneoPeer::ACTIVE, true);
|
|
|
|
$up = new Criteria();
|
|
$up->add(CeneoPeer::IS_BASKET, 1);
|
|
|
|
BasePeer::doUpdate($sel, $up, $con);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->redirect('stCeneoBackend/list?page=' . $this->getRequestParameter('page', 1));
|
|
}
|
|
|
|
|
|
|
|
|
|
public function executeDeleteAll()
|
|
{
|
|
$con = Propel::getConnection();
|
|
$sel = new Criteria();
|
|
$sel->add(CeneoPeer::ACTIVE, true);
|
|
$up = new Criteria();
|
|
$up->add(CeneoPeer::ACTIVE, false);
|
|
|
|
BasePeer::doUpdate($sel, $up, $con);
|
|
|
|
return $this->redirect('stCeneoBackend/list?page=' . $this->getRequestParameter('page', 1));
|
|
}
|
|
|
|
protected function getCeneoOrCreate($id = 'id')
|
|
{
|
|
$ceneo = CeneoPeer::retrieveByProduct($this->related_object);
|
|
|
|
if (null === $ceneo) {
|
|
if ($this->hasRequestParameter('id'))
|
|
{
|
|
return $this->redirect('@stCeneoPlugin?action=create&product_id=' . $this->related_object->getId().'&view=default');
|
|
}
|
|
else
|
|
{
|
|
$ceneo = new Ceneo();
|
|
$ceneo->setProduct($this->related_object);
|
|
}
|
|
}
|
|
|
|
return $ceneo;
|
|
}
|
|
|
|
public function executeGenerateCustom()
|
|
{
|
|
parent::executeGenerateCustom();
|
|
|
|
$i18n = $this->getContext()->getI18n();
|
|
$this->getBreadcrumbsBuilder()->getDefaultBreadcrumbs()->add($i18n->__('Generowanie pliku'));
|
|
}
|
|
|
|
|
|
} |