265 lines
8.9 KiB
PHP
265 lines
8.9 KiB
PHP
<?php
|
|
|
|
class stGoogleShoppingBackendActions extends autostGoogleShoppingBackendActions
|
|
{
|
|
public function executeList()
|
|
{
|
|
|
|
$config = stConfig::getInstance(sfContext::getInstance(), 'stSecurityBackend');
|
|
|
|
|
|
if ($config->get('ssl') != "shop")
|
|
{
|
|
|
|
$context = sfContext::getInstance();
|
|
|
|
$notice = $context->getI18N()->__('Do poprawnego działania Google Shopping niezbędne jest posiadanie certyfikatu SSL.') . "<br/>" .
|
|
$context->getI18N()->__('Jego brak może skutkować zawieszeniem konta Google Merchant.') . "<br/>" .
|
|
$context->getI18N()->__('Więcej informacji na ten temat można znaleźć na stronach pomocy') . " " .
|
|
'<a href="https://goo.gl/r3h2wO" target="_blank">Google Merchant Center</a>';
|
|
|
|
|
|
$this->setFlash("warning", $notice, false);
|
|
}
|
|
|
|
return parent::executeList();
|
|
}
|
|
|
|
public function executeGenerateCustom()
|
|
{
|
|
$config = stConfig::getInstance(sfContext::getInstance(), 'stSecurityBackend');
|
|
|
|
|
|
if ($config->get('ssl') != "shop")
|
|
{
|
|
|
|
$context = sfContext::getInstance();
|
|
|
|
$notice = $context->getI18N()->__('Do poprawnego działania Google Shopping niezbędne jest posiadanie certyfikatu SSL.') . "<br/>" .
|
|
$context->getI18N()->__('Jego brak może skutkować zawieszeniem konta Google Merchant.') . "<br/>" .
|
|
$context->getI18N()->__('Więcej informacji na ten temat można znaleźć na stronach pomocy') . " " .
|
|
'<a href="https://goo.gl/r3h2wO" target="_blank">Google Merchant Center</a>';
|
|
|
|
|
|
$this->setFlash("warning", $notice, false);
|
|
}
|
|
|
|
|
|
parent::executeGenerateCustom();
|
|
|
|
$i18n = $this->getContext()->getI18n();
|
|
$this->getBreadcrumbsBuilder()->getDefaultBreadcrumbs()->add($i18n->__('Generowanie pliku'));
|
|
}
|
|
|
|
public function executeConfig()
|
|
{
|
|
$config = stConfig::getInstance(sfContext::getInstance(), 'stSecurityBackend');
|
|
|
|
|
|
if ($config->get('ssl') != "shop")
|
|
{
|
|
|
|
$context = sfContext::getInstance();
|
|
|
|
$notice = $context->getI18N()->__('Do poprawnego działania Google Shopping niezbędne jest posiadanie certyfikatu SSL.') . "<br/>" .
|
|
$context->getI18N()->__('Jego brak może skutkować zawieszeniem konta Google Merchant.') . "<br/>" .
|
|
$context->getI18N()->__('Więcej informacji na ten temat można znaleźć na stronach pomocy') . " " .
|
|
'<a href="https://goo.gl/r3h2wO" target="_blank">Google Merchant Center</a>';
|
|
|
|
|
|
$this->setFlash("warning", $notice, false);
|
|
}
|
|
|
|
return parent::executeConfig();
|
|
}
|
|
|
|
|
|
protected function updateConfigFromRequest()
|
|
{
|
|
$config = $this->getRequestParameter('config');
|
|
foreach (stGoogleShopping::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("googleshopping", 1);
|
|
}
|
|
else
|
|
{
|
|
appAdsTracker::checkCompare("googleshopping", 0);
|
|
}
|
|
}
|
|
|
|
parent::updateConfigFromRequest();
|
|
}
|
|
|
|
protected function saveConfig()
|
|
{
|
|
parent::saveConfig();
|
|
|
|
stFunctionCache::clearFrontendModule('stProduct', 'product');
|
|
stTheme::clearSmartyCache(true);
|
|
stFastCacheManager::clearCache();
|
|
}
|
|
|
|
|
|
public function executeProductEnable()
|
|
{
|
|
$ids = $this->getRequestParameter('google_shopping[selected]', array());
|
|
|
|
foreach ($ids as $id)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(GoogleShoppingPeer::PRODUCT_ID, $id);
|
|
$googleShopping = GoogleShoppingPeer::doSelectOne($c);
|
|
|
|
if (null === $googleShopping)
|
|
{
|
|
$googleShopping = new GoogleShopping();
|
|
$googleShopping->setProductId($id);
|
|
}
|
|
|
|
$googleShopping->setActive(true);
|
|
$googleShopping->save();
|
|
}
|
|
|
|
return $this->redirect('stGoogleShoppingBackend/list?page=' . $this->getRequestParameter('page', 1));
|
|
}
|
|
|
|
public function executeProductDisable()
|
|
{
|
|
$ids = $this->getRequestParameter('google_shopping[selected]', array());
|
|
|
|
/**
|
|
* @var GoogleShopping $googleShopping
|
|
*/
|
|
foreach (GoogleShoppingPeer::retrieveByPKs(array_values($ids)) as $googleShopping)
|
|
{
|
|
$googleShopping->delete();
|
|
}
|
|
|
|
return $this->redirect('stGoogleShoppingBackend/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(GoogleShoppingPeer::ACTIVE, '');
|
|
$criterion->addOr($c->getNewCriterion(GoogleShoppingPeer::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(GoogleShoppingPeer::ACTIVE, '');
|
|
$criterion->addOr($c->getNewCriterion(GoogleShoppingPeer::ACTIVE, null, Criteria::ISNULL));
|
|
$c->add($criterion);
|
|
}
|
|
|
|
if ($this->filters['active'] == 1)
|
|
{
|
|
$c->add(GoogleShoppingPeer::ACTIVE, $this->filters['active']);
|
|
}
|
|
}
|
|
|
|
|
|
if ($this->filters)
|
|
{
|
|
$c->add(GoogleShoppingPeer::PRODUCT_ID, 0, Criteria::NOT_EQUAL);
|
|
}
|
|
|
|
$this->getDispatcher()->notify(new sfEvent($this, 'autoStGoogleShoppingBackendActions.addFiltersCriteria', array('criteria' => $c)));
|
|
}
|
|
|
|
public function executeAddAll()
|
|
{
|
|
GoogleShoppingPeer::doDeleteAll();
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
$con->executeQuery(sprintf(
|
|
"INSERT INTO %s(%s, %s) (SELECT %s, 1 FROM %s)",
|
|
GoogleShoppingPeer::TABLE_NAME,
|
|
GoogleShoppingPeer::PRODUCT_ID,
|
|
GoogleShoppingPeer::ACTIVE,
|
|
ProductPeer::ID,
|
|
ProductPeer::TABLE_NAME
|
|
));
|
|
|
|
return $this->redirect('stGoogleShoppingBackend/list?page=' . $this->getRequestParameter('page', 1));
|
|
}
|
|
|
|
public function executeDeleteAll()
|
|
{
|
|
GoogleShoppingPeer::doDeleteAll();
|
|
|
|
return $this->redirect('stGoogleShoppingBackend/list?page=' . $this->getRequestParameter('page', 1));
|
|
}
|
|
|
|
protected function getGoogleShoppingOrCreate($id = 'id')
|
|
{
|
|
$googleShopping = GoogleShoppingPeer::retrieveByProduct($this->related_object);
|
|
|
|
if (null === $googleShopping) {
|
|
if ($this->hasRequestParameter('id')) {
|
|
return $this->redirect('@stGoogleShoppingPlugin?action=create&product_id=' . $this->related_object->getId().'&view=default');
|
|
} else {
|
|
$googleShopping = new GoogleShopping();
|
|
$googleShopping->setProduct($this->related_object);
|
|
}
|
|
}
|
|
|
|
return $googleShopping;
|
|
}
|
|
|
|
}
|