diff --git a/src/FacebookPixel/FacebookPixel.php b/src/FacebookPixel/FacebookPixel.php index 7dddb46..e37a549 100755 --- a/src/FacebookPixel/FacebookPixel.php +++ b/src/FacebookPixel/FacebookPixel.php @@ -82,7 +82,7 @@ public function addToCart( ) { $this->sendEventToOutput( - $this->template->event = self::EVENT_ADD_TO_CART, + self::EVENT_ADD_TO_CART, $this->prepareProductsToParameters($contentIds, $contentName, $contentCategory, $value, $currency) ); } @@ -90,7 +90,7 @@ public function addToCart( public function purchase($value, $currency, $contentIds = null) { $this->sendEventToOutput( - $this->template->event = self::EVENT_PURCHASE, + self::EVENT_PURCHASE, $this->prepareProductsToParameters($contentIds, null, null, $value, $currency) ); } diff --git a/src/FacebookPixel/templates/facebookPixel.latte b/src/FacebookPixel/templates/facebookPixel.latte index 8eb7cf4..81c5341 100755 --- a/src/FacebookPixel/templates/facebookPixel.latte +++ b/src/FacebookPixel/templates/facebookPixel.latte @@ -1,21 +1,17 @@ - {if count($specialEvents)} - + {/if} diff --git a/tests/.gitignore b/tests/.gitignore index e7d2149..8b94733 100755 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,8 +1,9 @@ vendor composer.lock temp -!temp/.gitignore +!temp/cache/.htaccess log +!log/.htaccess tests/_temp tests/_log tests/_helpers \ No newline at end of file diff --git a/tests/app/presenters/HomepagePresenter.php b/tests/app/presenters/HomepagePresenter.php index 10485ad..816cf88 100644 --- a/tests/app/presenters/HomepagePresenter.php +++ b/tests/app/presenters/HomepagePresenter.php @@ -2,6 +2,7 @@ namespace App\Presenters; +use Eflyax\FacebookPixel\FacebookPixel; use Eflyax\FacebookPixel\FacebookPixelService; use Eflyax\FacebookPixel\IFacebookPixelFactory; use Nette\Application\UI\Presenter; @@ -17,41 +18,82 @@ class HomepagePresenter extends Presenter /** @var FacebookPixelService @inject */ public $facebookPixelService; + /** @var FacebookPixel */ + public $facebookPixel; + private $product; + private $currencyCode = 'CZK'; + protected function startup() { parent::startup(); + $this->facebookPixel = $this['facebookPixel']; $product = new \stdClass(); $product->id = 1; $product->price = 42; $product->title = 'Product title'; $product->description = 'Product description'; - $this->product = $product; } public function actionProductDetail() { - $this->template->product = $this->product; - $this->template->currencyCode = 'CZK'; + $this->facebookPixel->viewContent( + $this->product->id, + $this->product->title, + null, + $this->product->price, + $this->currencyCode + ); } public function actionPurchase() { - $this->template->totalPrice = $this->product->price + self::SHIPPING_PRICE; - $this->template->currencyCode = 'CZK'; - $this->template->productIds = [$this->product->id]; - $this->facebookPixelService->eventStart(FacebookPixelService::EVENT_PURCHASE); + $totalPrice = $this->product->price + self::SHIPPING_PRICE; + $this->facebookPixel->purchase($totalPrice, $this->currencyCode); } public function actionAddToCart() { // ..add product to shopping cart - $this->facebookPixelService->eventStart(FacebookPixelService::EVENT_ADD_TO_CART); + $this->facebookPixel->addToCart( + $this->product->id, + $this->product->title, + null, + $this->product->price, + $this->currencyCode + ); $this->redirect('ProductDetail'); } + public function actionAddToCartAndPurchase() + { + $totalPrice = $this->product->price + self::SHIPPING_PRICE; + $this->facebookPixel->addToCart( + $this->product->id, + $this->product->title, + null, + $this->product->price, + $this->currencyCode + ); + $this->facebookPixel->purchase($totalPrice, $this->currencyCode); + } + + public function actionAddToCartAndPurchaseWithRedirect() + { + $totalPrice = $this->product->price + self::SHIPPING_PRICE; + $this->facebookPixel->addToCart( + $this->product->id, + $this->product->title, + null, + $this->product->price, + $this->currencyCode + ); + $this->facebookPixel->purchase($totalPrice, $this->currencyCode); + $this->redirect('Homepage:'); + } + protected function createComponentFacebookPixel() { return $this->IFacebookPixelFactory->create(); diff --git a/tests/app/templates/@layout.latte b/tests/app/templates/@layout.latte index 8961386..7715ff4 100755 --- a/tests/app/templates/@layout.latte +++ b/tests/app/templates/@layout.latte @@ -1,17 +1,18 @@ - +
+