/** * Add Free payment method * * @param PaymentCollectionEvent $event Event */ public function addFreePaymentPaymentMethod(PaymentCollectionEvent $event) { if ($this->plugin->isUsable()) { $bankwire = new PaymentMethod($this->plugin->getHash(), 'elcodi_plugin.bankwire.name', 'elcodi_plugin.bankwire.description', $this->router->generate('paymentsuite_bankwire_execute')); $event->addPaymentMethod($bankwire); } }
/** * Add Free payment method * * @param PaymentCollectionEvent $event Event */ public function addFreePaymentPaymentMethod(PaymentCollectionEvent $event) { if ($this->plugin->isUsable()) { $freePayment = new PaymentMethod($this->plugin->getHash(), 'elcodi_plugin.free_payment.name', 'elcodi_plugin.free_payment.description', $this->router->generate('freepayment_payment_routes')); $event->addPaymentMethod($freePayment); } }
/** * Add PayPal payment method * * @param PaymentCollectionEvent $event Event */ public function addPaypalPaymentMethod(PaymentCollectionEvent $event) { if ($this->plugin->isUsable(['business'])) { $paypal = new PaymentMethod($this->plugin->getHash(), 'elcodi_plugin.paypal_web_checkout.name', 'elcodi_plugin.paypal_web_checkout.description', $this->router->generate('paymentsuite_paypal_web_checkout_execute')); $event->addPaymentMethod($paypal); } }
/** * Add Stripe payment method * * @param PaymentCollectionEvent $event Event */ public function addStripePaymentMethod(PaymentCollectionEvent $event) { if ($this->plugin->isUsable(['private_key', 'public_key'])) { $stripeForm = $this->getStripeForm() . $this->getStripeScript(); $stripe = new PaymentMethod($this->plugin->getHash(), 'elcodi_plugin.stripe.name', 'elcodi_plugin.stripe.description', '', '', $stripeForm); $event->addPaymentMethod($stripe); } }
/** * Renders import/export buttons * * @param EventInterface $event * * @return string */ public function renderButtons(EventInterface $event) { if ($event->get('entity_type') !== 'product') { return null; } if ($this->plugin->isUsable()) { $this->appendTemplate('ElcodiProductCsvBundle::buttons.html.twig', $event, $this->plugin); } }
/** * Given a Cart, return a set of Valid ShippingRanges satisfied. * * @param ShippingCollectionEvent $event Event * * @return $this Self object */ public function addCustomShippingMethods(ShippingCollectionEvent $event) { if (!$this->plugin->isEnabled()) { return $this; } $cart = $event->getCart(); $carrierRanges = $this->shippingRangesProvider->getAllShippingRangesSatisfiedWithCart($cart); foreach ($carrierRanges as $carrierRange) { $event->addShippingMethod(new ShippingMethod('custom-shipping-method-' . $carrierRange->getId(), $carrierRange->getCarrier()->getName(), $carrierRange->getName(), '', $carrierRange->getPrice())); } }
/** * Renders the share product button. * * @param EventInterface $event The event */ public function renderShareOrder(EventInterface $event) { if ($this->plugin->isUsable()) { $shareUrl = $this->urlGenerator->generate('store_homepage', [], true); $this->appendTemplate('@ElcodiFacebook/Post/share.html.twig', $event, $this->plugin, ['url' => $shareUrl]); } }
/** * Checks if the plugin should be disabled * * @param GetResponseEvent $event The response event */ public function handle(GetResponseEvent $event) { if ($this->plugin->isEnabled() && $this->wizardStatus->isWizardFinished()) { $this->plugin->setEnabled(false); $this->pluginObjectManager->flush($this->plugin); } }
/** * Renders the share product button. * * @param EventInterface $event The event */ public function renderShareOrder(EventInterface $event) { if ($this->plugin->isUsable(['twitter_account'])) { $shareUrl = $this->urlGenerator->generate('store_homepage', [], true); $this->appendTemplate('@ElcodiTwitter/Tweet/share.html.twig', $event, $this->plugin, ['url' => $shareUrl, 'text' => $this->translator->trans('twitter_plugin.tweet.take_look')]); } }
/** * Handles the event redirecting to the wizard if the user is visiting the * dashboard * * @param GetResponseEvent $event The response event */ public function handle(GetResponseEvent $event) { if ($this->plugin->isEnabled() && !$this->wizardStatus->isWizardFinished()) { $request = $event->getRequest(); $currentRoute = $this->getCurrentRequestRoute($request); if ('admin_homepage' == $currentRoute) { $event->setResponse(new RedirectResponse($this->urlGenerator->generate($this->wizardRoutes->getDefaultWizardRoute()))); } } }
/** * Render the disable under construction mode. * * @param EventInterface $event The event */ public function renderDisableUnderConstructionMode(EventInterface $event) { if ($this->plugin->isUsable()) { $masterRequest = $this->requestStack->getMasterRequest(); $currentRoute = $masterRequest->attributes->get('_route'); $isWizardFinished = $this->wizardStatus->isWizardFinished(); if ('admin_configuration_list' == $currentRoute && $isWizardFinished) { $this->appendTemplate('@ElcodiStoreSetupWizard/Wizard/disable-under-construction.html.twig', $event, $this->plugin); } } }
/** * Renders the follow button. * * @param EventInterface $event The event */ public function renderFollowButton(EventInterface $event) { if ($this->plugin->isUsable(['twitter_account'])) { $this->appendTemplate('@ElcodiTwitter/Follow/follow.html.twig', $event, $this->plugin); } }
/** * Renders the javascript. * * @param EventInterface $event The event */ public function renderJavascript(EventInterface $event) { if ($this->plugin->isUsable()) { $this->appendTemplate('@ElcodiTwitter/javascript.html.twig', $event, $this->plugin); } }
/** * Merge this plugin instance with a new one, and saves the result in * this instance. * * This method will give priority to its own properties values. * * @param Plugin $newPlugin New plugin configuration * * @return $this Self object */ public function merge(Plugin $newPlugin) { if ($newPlugin->getNamespace() !== $this->getNamespace()) { throw new RuntimeException('Both plugins cannot be merged'); } $this->configuration->merge($newPlugin->getConfiguration()); return $this; }
/** * Create or update existing plugin given a set of plugin instances and the * information to create a new one. * * @param string $pluginNamespace Plugin namespace * @param array $pluginConfiguration Plugin Configuration * * @return Plugin Plugin instance */ private function getPluginInstance($pluginNamespace, array $pluginConfiguration) { $pluginType = $pluginConfiguration['type']; $pluginCategory = $pluginConfiguration['category']; $pluginEnabledByDefault = $pluginConfiguration['enabled_by_default']; unset($pluginConfiguration['type']); $pluginInstance = Plugin::create($pluginNamespace, $pluginType, $pluginCategory, PluginConfiguration::create($pluginConfiguration), $pluginEnabledByDefault); return $pluginInstance; }
/** * Return route collection for injected plugins * * @return RouteCollection Collection generated */ protected function addPluginRoutesCollection(Plugin $plugin) { $routes = new RouteCollection(); $bundleName = $plugin->getBundleName(); $bundle = $this->kernel->getBundle($bundleName); $routingFilePath = '/Resources/config/routing.yml'; $resourcePath = $bundle->getPath() . $routingFilePath; $type = 'yaml'; if (file_exists($resourcePath)) { $routes->addCollection($this->import('@' . $bundle->getName() . $routingFilePath, $type)); } return $routes; }
/** * Check if, given a plugin hash, a configuration page is available * * @param Plugin $plugin Plugin * * @return boolean Is available */ protected function isPluginConfigurable(Plugin $plugin = null) { return $plugin instanceof Plugin && $plugin->hasFields(); }
/** * Renders import/export buttons * * @param EventInterface $event Event */ public function renderPin(EventInterface $event) { if ($this->plugin->isUsable()) { $this->appendTemplate('@ElcodiPinterest/product_pin.html.twig', $event, $this->plugin); } }
/** * Renders disqus block on product page * * @param EventInterface $event Event */ public function renderDisqusProductBlock(EventInterface $event) { if ($this->plugin->isUsable(['disqus_identifier', 'disqus_enabled_product'])) { $this->appendTemplate('@ElcodiDisqus/block.html.twig', $event, $this->plugin); } }
/** * Renders google analytics JS * * @param EventInterface $event Event */ public function renderJavascript(EventInterface $event) { if ($this->plugin->isUsable(['analytics_tracker_id'])) { $this->appendTemplate('@ElcodiGoogleAnalytics/javascript.html.twig', $event, $this->plugin); } }
/** * @return PluginNotFoundException */ public static function createPluginRouteNotFound(Plugin $plugin) { $message = sprintf('Elcodi cannot find plugin %s. Make sure it exists as a vendor by checking your composer, or load elcodi:install command in order to update the plugin database', $plugin->getNamespace()); return new static($message); }
/** * Test merge with exception. * * @expectedException \RuntimeException */ public function testMergeException() { $this->plugin->merge(Plugin::create('A\\Nother\\Plugin', 'plugin', 'social', PluginConfiguration::create(['name' => 'A Plugin', 'description' => 'A plugin description', 'fa_icon' => 'plugin_icon', 'fields' => ['field1' => ['type' => 'text', 'label' => 'label1', 'required' => true, 'data' => null, 'options' => []]]]), true)); }