Skip to content
This repository has been archived by the owner on May 30, 2019. It is now read-only.

Commit

Permalink
Tweet on thanks order page
Browse files Browse the repository at this point in the history
  • Loading branch information
rogergros committed Mar 18, 2015
1 parent c559640 commit d0223cf
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AdminController extends Controller
/**
* Configure plugin action page
*
* @param Request $request The current request
* @param Request $request The current request
*
* @return array|RedirectResponse The response
*
Expand Down
6 changes: 3 additions & 3 deletions src/Elcodi/Plugin/TwitterBundle/Resources/config/classes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ parameters:
#
# Templating
#
elcodi_plugin.javascript_renderer.class: Elcodi\Plugin\TwitterBundle\Templating\JavascriptRenderer
elcodi_plugin.share_tweet_renderer.class: Elcodi\Plugin\TwitterBundle\Templating\ShareTweetRenderer
elcodi_plugin.follow_renderer.class: Elcodi\Plugin\TwitterBundle\Templating\FollowRenderer
elcodi_plugin.twitter.javascript_renderer.class: Elcodi\Plugin\TwitterBundle\Templating\JavascriptRenderer
elcodi_plugin.twitter.share_tweet_renderer.class: Elcodi\Plugin\TwitterBundle\Templating\ShareTweetRenderer
elcodi_plugin.twitter.follow_renderer.class: Elcodi\Plugin\TwitterBundle\Templating\FollowRenderer
10 changes: 7 additions & 3 deletions src/Elcodi/Plugin/TwitterBundle/Resources/config/templating.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
# Twig renderer
#
elcodi_plugin.twitter.javascript_renderer:
class: %elcodi_plugin.javascript_renderer.class%
class: %elcodi_plugin.twitter.javascript_renderer.class%
calls:
- [setTemplating, [@twig]]
- [setPlugin, [@=elcodi_plugin("Elcodi\\Plugin\\TwitterBundle")]]
Expand All @@ -13,16 +13,20 @@ services:
- { name: kernel.event_listener, event: admin.footer_script, method: renderJavascript }

elcodi_plugin.twitter.share_tweet_renderer:
class: %elcodi_plugin.share_tweet_renderer.class%
class: %elcodi_plugin.twitter.share_tweet_renderer.class%
arguments:
url_generator: @router
translator: @translator
calls:
- [setTemplating, [@twig]]
- [setPlugin, [@=elcodi_plugin("Elcodi\\Plugin\\TwitterBundle")]]
tags:
- { name: kernel.event_listener, event: store.product_pin_top, method: renderShareProduct }
- { name: kernel.event_listener, event: admin.product_top, method: renderShareProduct }
- { name: kernel.event_listener, event: store.order_thanks, method: renderShareOrder }

elcodi_plugin.twitter.follow_renderer:
class: %elcodi_plugin.follow_renderer.class%
class: %elcodi_plugin.twitter.follow_renderer.class%
calls:
- [setTemplating, [@twig]]
- [setPlugin, [@=elcodi_plugin("Elcodi\\Plugin\\TwitterBundle")]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ twitter_plugin:
section:
settings:
title: Twitter configuration
tweet:
take_look: Take a look at
error:
is_disabled: The plugin is disabled
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ twitter_plugin:
section:
settings:
title: Configuración de Twitter
tweet:
take_look: Echa un vistazo a
error:
is_disabled: El plugin está desactivado
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<a
href="https://twitter.com/share"
class="twitter-share-button"
data-url="{{ url('store_product_view', { id: product.id, slug: product.slug }) }}"
data-text="{{ product.name }}"
data-url="{{ url }}"
data-text="{{ text }}"
{% if twitter_account %}
data-via="{{ twitter_account }}"
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@

namespace Elcodi\Plugin\TwitterBundle\Templating;

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Translation\TranslatorInterface;

use Elcodi\Component\Plugin\Entity\Plugin;
use Elcodi\Component\Plugin\Interfaces\EventInterface;
use Elcodi\Component\Plugin\Templating\Traits\TemplatingTrait;
use Elcodi\Component\Product\Entity\Interfaces\CategoryInterface;
use Elcodi\Component\Product\Entity\Product;

class ShareTweetRenderer
{
Expand All @@ -32,6 +37,34 @@ class ShareTweetRenderer
*/
protected $plugin;

/**
* @var UrlGeneratorInterface
*
* An url generator
*/
protected $urlGenerator;

/**
* @var Translator
*
* A translator
*/
protected $translator;

/**
* Builds a new share tweet renderer class.
*
* @param UrlGeneratorInterface $urlGenerator An url generator
* @param TranslatorInterface $translator A translator
*/
public function __construct(
UrlGeneratorInterface $urlGenerator,
TranslatorInterface $translator
) {
$this->urlGenerator = $urlGenerator;
$this->translator = $translator;
}

/**
* Set plugin
*
Expand All @@ -56,10 +89,66 @@ public function renderShareProduct(EventInterface $event)
if ($this->plugin->isEnabled()) {
$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,
[
'url' => $shareUrl,
'text' => $text,
'twitter_account' => $pluginConfiguration['twitter_account'],
]
);
}
}

/**
* Renders the share product button.
*
* @param EventInterface $event The event
*/
public function renderShareOrder(EventInterface $event)
{
if ($this->plugin->isEnabled()) {
$pluginConfiguration = $this->plugin->getConfiguration();

$shareUrl = $this
->urlGenerator
->generate(
'store_homepage',
[],
true
);

$this->appendTemplate(
'@ElcodiTwitter/Tweet/share.html.twig',
$event,
['twitter_account' => $pluginConfiguration['twitter_account']]
[
'url' => $shareUrl,
'text' => $this->translator->trans('twitter_plugin.tweet.take_look'),
'twitter_account' => $pluginConfiguration['twitter_account'],
]
);
}
}
Expand Down

0 comments on commit d0223cf

Please sign in to comment.