Skip to content

Commit

Permalink
Updated to new Pluginstruct & Fixed Shopscope (#3)
Browse files Browse the repository at this point in the history
* Updated to new Pluginstruct & Fixed Shopscope

* after merge

* optimized config read

* optimized config read & cs fixer

* optimized config read & cs fixer

* removed comment

* changelog
  • Loading branch information
pwnyprod authored and jochenmanz committed Jul 12, 2017
1 parent a651e4e commit 7efbdb1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="arv_google_certified_shops_new.subscriber.frontend" class="ArvGoogleCertifiedShops\Subscriber\Frontend">
<argument type="service" id="shopware.plugin.cached_config_reader" />
<argument type="service" id="service_container" />

<tag name="shopware.event_subscriber"/>
</service>
</services>
Expand Down
73 changes: 56 additions & 17 deletions Subscriber/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,48 @@
namespace ArvGoogleCertifiedShops\Subscriber;

use Enlight\Event\SubscriberInterface;
use \Exception;
use \Zend_Date;
use Exception;
use Shopware\Components\Plugin\CachedConfigReader;
use Shopware\Components\Plugin\ConfigReader;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Zend_Date;

class Frontend implements SubscriberInterface
{
/**
* @var CachedConfigReader|ConfigReader
*/
private $configReader;

/**
* @var ContainerInterface
*/
private $container;

/**
* Frontend constructor.
*
* @param CachedConfigReader|ConfigReader $configReader
* @param ContainerInterface $container
*/
public function __construct(ConfigReader $configReader, ContainerInterface $container)
{
$this->configReader = $configReader;
$this->container = $container;
}

public static function getSubscribedEvents()
{
return array(
'Enlight_Controller_Action_PostDispatch_Frontend' => 'onPostDispatch'
);
return [
'Enlight_Controller_Action_PostDispatch_Frontend' => 'onPostDispatch',
];
}

/**
* Event listener method
*
* @param \Enlight_Controller_ActionEventArgs $args
*
* @throws \Zend_Date_Exception
* @throws \Exception
*/
Expand All @@ -31,10 +57,7 @@ public function onPostDispatch(\Enlight_Controller_ActionEventArgs $args)
return;
}

$config = Shopware()->Container()->get('shopware.plugin.config_reader')->getByPluginName('ArvGoogleCertifiedShops');

$value = $config['TRUSTED_STORE_ID'];
if (empty($value)) {
if ($this->getConfigVar('TRUSTED_STORE_ID')) {
return;
}

Expand All @@ -54,23 +77,39 @@ public function onPostDispatch(\Enlight_Controller_ActionEventArgs $args)

try {
$now = new Zend_Date();
$dateShipping = $now->addDay($config['ORDER_EST_SHIP_DATE'])->toString('YYYY-MM-dd');
$dateShipping = $now->addDay($this->getConfigVar('ORDER_EST_SHIP_DATE'))->toString('YYYY-MM-dd');

$now = new Zend_Date();
$dateDelivery = $now->addDay($config['ORDER_EST_DELIVERY_DATE'])->toString('YYYY-MM-dd');
$dateDelivery = $now->addDay($this->getConfigVar('ORDER_EST_DELIVERY_DATE'))->toString('YYYY-MM-dd');
} catch (Exception $e) {
$dateShipping = $dateDelivery = new Zend_Date();
}
$view->assign('ARV_GTS_TRUSTED_STORE_ID', $config['TRUSTED_STORE_ID']);
$view->assign('ARV_GTS_BADGE_POSITION', $config['BADGE_POSITION']);
$view->assign('ARV_GTS_TRUSTED_STORE_ID', $this->getConfigVar('TRUSTED_STORE_ID'));
$view->assign('ARV_GTS_BADGE_POSITION', $this->getConfigVar('BADGE_POSITION'));
$view->assign('ARV_GTS_LOCALE', Shopware()->Locale()->toString());
$view->assign('ARV_GTS_COUNTRY', Shopware()->Locale()->getRegion());
$view->assign('ARV_GTS_MERCHANT_ORDER_DOMAIN', $config['MERCHANT_ORDER_DOMAIN']);
$view->assign('ARV_GTS_MERCHANT_ORDER_DOMAIN', $this->getConfigVar('MERCHANT_ORDER_DOMAIN'));
$view->assign('ARV_GTS_ORDER_EST_SHIP_DATE', $dateShipping);
$view->assign('ARV_GTS_ORDER_EST_DELIVERY_DATE', $dateDelivery);
$view->assign('ARV_GTS_BASKET_CURRENCY', Shopware()->Currency()->getShortName());
$view->assign('ARV_GTS_GOOGLE_SHOPPING_ACCOUNT_ID', $config['GOOGLE_SHOPPING_ACCOUNT_ID']);
$view->assign('ARV_GTS_GOOGLE_SHOPPING_COUNTRY', $config['GOOGLE_SHOPPING_COUNTRY']);
$view->assign('ARV_GTS_GOOGLE_GOOGLE_SHOPPING_LANGUAGE', $config['GOOGLE_SHOPPING_LANGUAGE']);
$view->assign('ARV_GTS_GOOGLE_SHOPPING_ACCOUNT_ID', $this->getConfigVar('GOOGLE_SHOPPING_ACCOUNT_ID'));
$view->assign('ARV_GTS_GOOGLE_SHOPPING_COUNTRY', $this->getConfigVar('GOOGLE_SHOPPING_COUNTRY'));
$view->assign('ARV_GTS_GOOGLE_GOOGLE_SHOPPING_LANGUAGE', $this->getConfigVar('GOOGLE_SHOPPING_LANGUAGE'));
}

/**
* @param string $var
* @param bool|string $default
*
* @return bool|string
*/
private function getConfigVar($var, $default = false)
{
$config = $this->configReader->getByPluginName('ArvGoogleRemarketing', $this->container->get('shop'));
if (empty($config[$var])) {
return $default;
}

return $config[$var];
}
}
6 changes: 5 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:noNamespaceSchemaLocation="../../../engine/Shopware/Components/Plugin/schema/plugin.xsd">
<label lang="de">Google Certified Shops</label>
<label lang="en">Google Certified Shops</label>
<version>2.0.0</version>
<version>2.1.0</version>
<copyright>Copyright © 2015, arvatis media GmbH</copyright>
<license>commercial</license>
<link>http://www.arvatis.com/</link>
Expand Down Expand Up @@ -31,4 +31,8 @@
<changes lang="de">Wiederveröffentlichung</changes>
<changes lang="en">Rerelease</changes>
</changelog>
<changelog version="2.1.0">
<changes lang="de">Ladeverhalten der Config optimiert</changes>
<changes lang="en">Fixed Config loadingbehavior</changes>
</changelog>
</plugin>

0 comments on commit 7efbdb1

Please sign in to comment.