Example #1
0
 /**
  * Renders the share product button.
  *
  * @param EventInterface $event The event
  */
 public function renderShareProduct(EventInterface $event)
 {
     if ($this->plugin->isUsable(['twitter_account'])) {
         $pluginConfiguration = $this->plugin->getConfiguration();
         /**
          * @var Product $product
          */
         $product = $event->get('product');
         $shareUrl = $this->urlGenerator->generate('store_product_view', ['id' => $product->getId(), 'slug' => $product->getSlug()], true);
         $text = $product->getName();
         $category = $product->getPrincipalCategory();
         if ($category instanceof CategoryInterface) {
             $text = $category->getName() . ' - ' . $text;
         }
         $this->appendTemplate('@ElcodiTwitter/Tweet/share.html.twig', $event, $this->plugin, ['url' => $shareUrl, 'text' => $text, 'twitter_account' => $pluginConfiguration->getField('twitter_account')]);
     }
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * Test get field value.
  */
 public function testGetFieldValue()
 {
     $this->assertEquals(null, $this->plugin->getFieldValue('field1'));
     $this->plugin->getConfiguration()->setFieldValue('field1', 'New value');
     $this->assertEquals('New value', $this->plugin->getFieldValue('field1'));
 }