Skip to content
This repository was archived by the owner on Sep 1, 2021. It is now read-only.

Commit 50b5bb4

Browse files
committed
Bugfix: Now listening on commerce_cart.onAddToCart
1 parent 0dd8e7c commit 50b5bb4

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

FbPixelPlugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getDocumentationUrl()
3333

3434
public function getVersion()
3535
{
36-
return '0.0.5';
36+
return '0.0.6';
3737
}
3838

3939
public function getDeveloper()

releases.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[
22
{
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"downloadUrl": "https://github.com/moment-inc/craft-fbpixel/archive/master.zip",
55
"date": "2017-08-11T11:00:00-12:00",
66
"notes": [
7+
"[Fixed] It should only run migrations when the Schema version is updated now",
78
"[Fixed] Make sure plugin doesn't run and warn user that commerce isn't installed.",
8-
"[Fixed] It should only run migrations when the Schema version is updated now"
9+
"[Fixed] Now listening on commerce_cart.onAddToCart"
910
]
1011
}
1112
]

services/FbPixel_AddToCartService.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ class FbPixel_AddToCartService extends BaseApplicationComponent
1111
public function listen()
1212
{
1313
craft()->on('multiAdd_cart.MultiAddToCart', [
14-
craft()->fbPixel_addToCart, 'addFlash'
14+
$this, 'onMultiAddToCartHandler'
15+
]);
16+
17+
craft()->on('commerce_cart.onAddToCart', [
18+
$this, 'onAddToCartHandler'
1519
]);
1620

1721
craft()->fbPixel_addToCart->checkFlash();
@@ -32,10 +36,20 @@ public function addHook()
3236
]);
3337
}
3438

35-
public function addFlash($event)
39+
public function onAddToCartHandler($event)
40+
{
41+
$lineItem = $event->params['lineItem'];
42+
$this->addFlash([$lineItem]);
43+
}
44+
45+
public function onMultiAddToCartHandler($event)
3646
{
3747
$lineItems = $event->params['lineItems'];
48+
$this->addFlash($lineItems);
49+
}
3850

51+
public function addFlash($lineItems)
52+
{
3953
$variantIds = craft()->userSession->getFlash(self::FLASH_NAME);
4054

4155
if (empty($variantIds)) {
@@ -44,7 +58,7 @@ public function addFlash($event)
4458

4559
$variantIds = array_merge(
4660
$variantIds,
47-
$this->getVariantIds($event->params['lineItems'])
61+
$this->getVariantIds($lineItems)
4862
);
4963

5064
craft()->userSession->setFlash(self::FLASH_NAME, $variantIds);

0 commit comments

Comments
 (0)