Skip to content

Commit

Permalink
RATEPLUG-145: add composer compatibility + fix a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy committed Oct 21, 2020
1 parent 7a259ca commit 05c820d
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 189 deletions.
157 changes: 61 additions & 96 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@
* file that was distributed with this source code.
*/

use RpayRatePay\Bootstrapping\AdditionalOrderAttributeSetup;
use RpayRatePay\Bootstrapping\CronjobSetup;
use RpayRatePay\Bootstrapping\DatabaseSetup;
use RpayRatePay\Bootstrapping\DeliveryStatusesSetup;
use RpayRatePay\Bootstrapping\Events\AssetsSubscriber;
use RpayRatePay\Bootstrapping\Events\BackendOrderControllerSubscriber;
use RpayRatePay\Bootstrapping\Events\BackendOrderViewExtensionSubscriber;
use RpayRatePay\Bootstrapping\Events\BogxProductConfiguratorSubscriber;
use RpayRatePay\Bootstrapping\Events\CheckoutValidationSubscriber;
use RpayRatePay\Bootstrapping\Events\LoggingControllerSubscriber;
use RpayRatePay\Bootstrapping\Events\OrderDetailControllerSubscriber;
use RpayRatePay\Bootstrapping\Events\OrderDetailsProcessSubscriber;
use RpayRatePay\Bootstrapping\Events\OrderOperationsSubscriber;
use RpayRatePay\Bootstrapping\Events\OrderViewExtensionSubscriber;
use RpayRatePay\Bootstrapping\Events\PaymentControllerSubscriber;
use RpayRatePay\Bootstrapping\Events\PaymentFilterSubscriber;
use RpayRatePay\Bootstrapping\Events\PluginConfigurationSubscriber;
use RpayRatePay\Bootstrapping\Events\TemplateExtensionSubscriber;
use RpayRatePay\Bootstrapping\Events\UpdateTransactionsSubscriber;
use RpayRatePay\Bootstrapping\FormsSetup;
use RpayRatePay\Bootstrapping\MenuesSetup;
use RpayRatePay\Bootstrapping\PaymentsSetup;
use RpayRatePay\Bootstrapping\PaymentStatusesSetup;
use RpayRatePay\Bootstrapping\ShopConfigSetup;
use RpayRatePay\Bootstrapping\TranslationsSetup;
use RpayRatePay\Bootstrapping\UserAttributeSetup;
use RpayRatePay\Component\Service\ConfigLoader;
use RpayRatePay\Component\Service\Logger;

require_once __DIR__ . '/Component/CSRFWhitelistAware.php';
Expand Down Expand Up @@ -100,39 +127,28 @@ public function install()
{
parent::install();

Logger::singleton()->info('INSTALL Plugin Bootstrap');

Logger::singleton()->info('Ratepay: event subscription');
$this->subscribeEvent(
'Enlight_Controller_Front_StartDispatch',
'onRegisterSubscriber'
);
$this->subscribeEvent(
'Shopware_Console_Add_Command',
'onRegisterSubscriber'
);
$this->subscribeEvent('Enlight_Controller_Front_StartDispatch', 'onRegisterSubscriber');
$this->subscribeEvent('Shopware_Console_Add_Command', 'onRegisterSubscriber');

$queue = [
new \RpayRatePay\Bootstrapping\PaymentsSetup($this),
new \RpayRatePay\Bootstrapping\FormsSetup($this),
new \RpayRatePay\Bootstrapping\TranslationsSetup($this),
new \RpayRatePay\Bootstrapping\MenuesSetup($this),
new \RpayRatePay\Bootstrapping\DatabaseSetup($this),
new \RpayRatePay\Bootstrapping\PaymentStatusesSetup($this),
new \RpayRatePay\Bootstrapping\DeliveryStatusesSetup($this),
new \RpayRatePay\Bootstrapping\CronjobSetup($this),
new \RpayRatePay\Bootstrapping\AdditionalOrderAttributeSetup($this),
new \RpayRatePay\Bootstrapping\UserAttributeSetup($this)
new PaymentsSetup($this),
new FormsSetup($this),
new DatabaseSetup($this),
new TranslationsSetup($this),
new MenuesSetup($this),
new ShopConfigSetup($this),
new CronjobSetup($this),
new AdditionalOrderAttributeSetup($this),
new PaymentStatusesSetup($this),
new DeliveryStatusesSetup($this),
new UserAttributeSetup($this)
];

Logger::singleton()->info('Ratepay: bootstrap routines');
foreach ($queue as $bootstrapper) {
$bootstrapper->install();
Logger::singleton()->info('[OK] ' . get_class($bootstrapper));
}

$this->Plugin()->setActive(true);
Logger::singleton()->info('Ratepay: Successful module installation');

return [
'success' => true,
Expand All @@ -144,65 +160,14 @@ public function install()
}

/**
* Updates the Plugin and its components
*
* @param string $version
* @return array|bool
* @throws exception
* @todo: implement translation update while updating
* @throws Exception
*/
public function update($version)
{
$this->subscribeEvent(
'Enlight_Controller_Front_StartDispatch',
'onRegisterSubscriber'
);
$this->subscribeEvent(
'Shopware_Console_Add_Command',
'onRegisterSubscriber'
);

Logger::singleton()->info('UPDATE Plugin Bootstrap ' . $version);
$queue = [
new \RpayRatePay\Bootstrapping\FormsSetup($this),
new \RpayRatePay\Bootstrapping\DatabaseSetup($this),
new \RpayRatePay\Bootstrapping\TranslationsSetup($this),
new \RpayRatePay\Bootstrapping\PaymentsSetup($this),
new \RpayRatePay\Bootstrapping\ShopConfigSetup($this),
new \RpayRatePay\Bootstrapping\CronjobSetup($this),
new \RpayRatePay\Bootstrapping\AdditionalOrderAttributeSetup($this),
new \RpayRatePay\Bootstrapping\PaymentStatusesSetup($this),
new \RpayRatePay\Bootstrapping\DeliveryStatusesSetup($this),
new \RpayRatePay\Bootstrapping\UserAttributeSetup($this)
];

$this->_dropOrderAdditionalAttributes();

Logger::singleton()->info('Ratepay: bootstrap routines');
foreach ($queue as $bootstrapper) {
$bootstrapper->update();
Logger::singleton()->info('[OK] ' . get_class($bootstrapper));
}

Logger::singleton()->info('Ratepay: Successful module update');
Logger::singleton()->addNotice('Successful module update');

return [
'success' => true,
'invalidateCache' => ['frontend', 'backend']
];
}

/**
* drops additional attributes for ratepay orders in s_order_attributes
*/
public function _dropOrderAdditionalAttributes()
{
$metaDataCache = Shopware()->Models()->getConfiguration()->getMetadataCacheImpl();
$metaDataCache->deleteAll();
Shopware()->Models()->generateAttributeModels(
['s_order_attributes']
);
Shopware()->Db()->executeUpdate("DELETE FROM `s_core_subscribes` WHERE `listener` LIKE '%".__CLASS__."::add%Files%'");
return $this->install();
}

/**
Expand All @@ -215,8 +180,8 @@ public function uninstall()
{
Logger::singleton()->info('UNINSTALL Plugin Bootstrap ');
$queue = [
new \RpayRatePay\Bootstrapping\DatabaseSetup($this),
new \RpayRatePay\Bootstrapping\UserAttributeSetup($this)
new DatabaseSetup($this),
new UserAttributeSetup($this)
];

$this->disable();
Expand Down Expand Up @@ -246,28 +211,28 @@ public function disable()
public function onRegisterSubscriber()
{
$subscribers = [
new \RpayRatePay\Bootstrapping\Events\OrderOperationsSubscriber(),
new \RpayRatePay\Bootstrapping\Events\TemplateExtensionSubscriber($this->Path()),
new \RpayRatePay\Bootstrapping\Events\PaymentControllerSubscriber($this->Path()),
new \RpayRatePay\Bootstrapping\Events\LoggingControllerSubscriber($this->Path()),
new \RpayRatePay\Bootstrapping\Events\OrderDetailControllerSubscriber($this->Path()),
new \RpayRatePay\Bootstrapping\Events\CheckoutValidationSubscriber($this->Path()),
new \RpayRatePay\Bootstrapping\Events\PaymentFilterSubscriber(),
new \RpayRatePay\Bootstrapping\Events\PluginConfigurationSubscriber($this->getName()),
new \RpayRatePay\Bootstrapping\Events\OrderDetailsProcessSubscriber(),
new \RpayRatePay\Bootstrapping\Events\JavascriptSourceSubscriber($this->Path()),
new \RpayRatePay\Bootstrapping\Events\OrderViewExtensionSubscriber($this->Path()),
new \RpayRatePay\Bootstrapping\Events\UpdateTransactionsSubscriber(),
new \RpayRatePay\Bootstrapping\Events\BackendOrderControllerSubscriber(new \RpayRatePay\Component\Service\ConfigLoader($this->get('db')), $this->Path()),
new \RpayRatePay\Bootstrapping\Events\BackendOrderViewExtensionSubscriber($this->Path()),
new \RpayRatePay\Bootstrapping\Events\BogxProductConfiguratorSubscriber()
new OrderOperationsSubscriber(),
new TemplateExtensionSubscriber($this->Path()),
new PaymentControllerSubscriber($this->Path()),
new LoggingControllerSubscriber($this->Path()),
new OrderDetailControllerSubscriber($this->Path()),
new CheckoutValidationSubscriber($this->Path()),
new PaymentFilterSubscriber(),
new PluginConfigurationSubscriber($this->getName()),
new OrderDetailsProcessSubscriber(),
new AssetsSubscriber($this->Path()),
new OrderViewExtensionSubscriber($this->Path()),
new UpdateTransactionsSubscriber(),
new BackendOrderControllerSubscriber(new ConfigLoader($this->get('db')), $this->Path()),
new BackendOrderViewExtensionSubscriber($this->Path()),
new BogxProductConfiguratorSubscriber()
];

$eventManager = Shopware()->Events();

foreach ($subscribers as $subscriber) {
$eventManager->addSubscriber($subscriber);
// Logger::singleton()->info('[OK] ' . get_class($subscriber));
}
}

}
2 changes: 1 addition & 1 deletion Bootstrapping/AdditionalOrderAttributeSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ protected function installAttributes()

protected function uninstallAttributes()
{
// $service->delete('s_articles_attributes', 'my_column');

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

namespace RpayRatePay\Bootstrapping\Events;

class JavascriptSourceSubscriber implements \Enlight\Event\SubscriberInterface
use Doctrine\Common\Collections\ArrayCollection;
use Shopware\Components\Theme\LessDefinition;

class AssetsSubscriber implements \Enlight\Event\SubscriberInterface
{
/**
* @var string
Expand All @@ -28,20 +31,33 @@ public static function getSubscribedEvents()
{
return [
'Theme_Compiler_Collect_Plugin_Javascript' => 'addJsFiles',
'Theme_Compiler_Collect_Plugin_Less' => 'addLessFiles'
];
}

/**
* Add base javascripts
*
* @return \Doctrine\Common\Collections\ArrayCollection
* @return ArrayCollection
*/
public function addJsFiles()
{
$jsPath = [
$this->path . 'Views/responsive/frontend/_public/src/javascripts/jquery.ratepay_checkout.js'
];
return new ArrayCollection([
$this->path . 'Views/frontend/_public/src/js/jquery.ratepay_checkout.js'
]);
}

return new \Doctrine\Common\Collections\ArrayCollection($jsPath);
/**
* @return ArrayCollection
*/
public function addLessFiles()
{
return new ArrayCollection([
new LessDefinition(
[],
[$this->path . '/Views/frontend/_public/src/less/all.less'],
$this->path
),
]);
}
}
18 changes: 10 additions & 8 deletions Bootstrapping/Events/PaymentFilterSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ public function filterPayments(\Enlight_Event_EventArgs $arguments)
$backend = false;
$config = $this->getRatePayPluginConfigByCountry($shopId, $countryBilling, $backend);
$paymentRepo = Shopware()->Models()->getRepository(Payment::class);
foreach ($config as $payment => $data) {
$paymentModel = $paymentRepo->findOneBy(['name' => $payment]);
foreach (RatepayHelper::getPaymentMethods() as $paymentMethodName) {
$data = isset($config[$paymentMethodName]) ? $config[$paymentMethodName] : null;

if ($paymentModel === null || ((int)$data['status']) !== 2) {
$paymentModel = $paymentRepo->findOneBy(['name' => $paymentMethodName]);
if ($paymentModel === null || $data === null || ((int)$data['status']) !== 2) {
unset($return[$paymentModel->getId()]);
continue;
}

if (PaymentMethodsService::getInstance()->isPaymentMethodLockedForCustomer($user, $payment)) {
if (PaymentMethodsService::getInstance()->isPaymentMethodLockedForCustomer($user, $paymentMethodName)) {
// the payment method is locked for the customer
unset($return[$paymentModel->getId()]);
continue;
Expand Down Expand Up @@ -144,17 +145,18 @@ public function filterPayments(\Enlight_Event_EventArgs $arguments)
continue;
}

$isB2b = $basket = false;
if (Shopware()->Modules()->Basket()) {
$basket = Shopware()->Modules()->Basket()->sGetAmount();
$basket = $basket['totalAmount']; //is this always brutto?
Logger::singleton()->info('BasketAmount: ' . $basket);
$isB2b = $validation->isCompanyNameSet();

if (!ValidationService::areAmountsValid($isB2b, $data, $basket)) {
unset($return[$paymentModel->getId()]);
continue;
}
}
if ($basket === false || !ValidationService::areAmountsValid($isB2b, $data, $basket)) {
unset($return[$paymentModel->getId()]);
continue;
}
}

Expand Down
1 change: 0 additions & 1 deletion Bootstrapping/Events/TemplateExtensionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public function extendTemplates(\Enlight_Event_EventArgs $args)
}
$view->assign('ratepaySandbox', $sandbox);

$view->extendsTemplate('frontend/payment_rpay_part/index/header.tpl');
$view->extendsTemplate('frontend/payment_rpay_part/index/index.tpl');
$view->extendsTemplate('frontend/payment_rpay_part/checkout/confirm.tpl');

Expand Down
Binary file added Views/frontend/_public/src/images/loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 05c820d

Please sign in to comment.