first commit
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/appFacebookRemarketingPlugin
|
||||
*
|
||||
*
|
||||
* @package appFacebookRemarketingPlugin
|
||||
* @author Pawel Byszewski <pawel@apes-apps.com>
|
||||
*/
|
||||
|
||||
class appFacebookRemarketingFrontendComponents extends sfComponents
|
||||
{
|
||||
public function executeFbremarketing()
|
||||
{
|
||||
|
||||
$config = stConfig::getInstance('appFacebookRemarketingBackend');
|
||||
|
||||
$this->fbremarketingConfig = $config->load();
|
||||
|
||||
$this->fbremarketingConfig['code_fbremarketing'] = $config->get('code_fbremarketing', null, true);
|
||||
|
||||
if ($this->fbremarketingConfig['enable_fbremarketing'] != 1 || $this->fbremarketingConfig['code_fbremarketing'] == null)
|
||||
{
|
||||
return sfView::NONE;
|
||||
}
|
||||
|
||||
if ((sfContext::getInstance()->getActionName()=="show") && (sfContext::getInstance()->getModuleName()=="stProduct") && $this->fbremarketingConfig['product_card'] == 1)
|
||||
{
|
||||
$this->product_card = 1;
|
||||
|
||||
$this->product = sfContext::getInstance()->getActionStack()->getLastEntry()->getActionInstance()->product;
|
||||
|
||||
}
|
||||
|
||||
if ((sfContext::getInstance()->getActionName()=="summary") && (sfContext::getInstance()->getModuleName()=="stOrder") && $this->fbremarketingConfig['order'] == 1)
|
||||
{
|
||||
$this->orders = 1;
|
||||
|
||||
if (!sfContext::getInstance()->getUser()->getAttribute("fb_browser_send_purchase")) {
|
||||
|
||||
sfContext::getInstance()->getUser()->setAttribute("fb_browser_send_purchase", true);
|
||||
|
||||
$this->order = sfContext::getInstance()->getActionStack()->getLastEntry()->getActionInstance()->order;
|
||||
|
||||
}else{
|
||||
return sfView::NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ((sfContext::getInstance()->getActionName()=="index") && (sfContext::getInstance()->getModuleName()=="stBasket") && $this->fbremarketingConfig['basket'] == 1) {
|
||||
$this->basket = 1;
|
||||
|
||||
$this->items = $this->getUser()->getBasket()->getlastAddedItems();
|
||||
|
||||
$this->currency = stCurrency::getInstance(sfContext::getInstance())->get();
|
||||
|
||||
}
|
||||
|
||||
$this->smarty = new stSmarty('appFacebookRemarketingFrontend');
|
||||
|
||||
}
|
||||
|
||||
public function executeFbAddTrack() {
|
||||
|
||||
$config = stConfig::getInstance('appFacebookRemarketingBackend');
|
||||
|
||||
$this->fbremarketingConfig = $config->load();
|
||||
|
||||
$this->fbremarketingConfig['code_fbremarketing'] = $config->get('code_fbremarketing', null, true);
|
||||
|
||||
if ($this->fbremarketingConfig['enable_fbremarketing'] != 1 || $this->fbremarketingConfig['code_fbremarketing'] == null || $this->fbremarketingConfig['cart'] != 1)
|
||||
{
|
||||
return sfView::NONE;
|
||||
}
|
||||
|
||||
$this->items = $this->getUser()->getBasket()->getlastAddedItems();
|
||||
|
||||
$this->currency = stCurrency::getInstance(sfContext::getInstance())->get();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
$event_id = sfContext::getInstance()->getUser()->getAttribute("fb_api_AddToCart");
|
||||
|
||||
if ($event_id=="") {
|
||||
$event_id = "0".mt_rand(100000, 999999);
|
||||
}
|
||||
|
||||
?>
|
||||
<script>
|
||||
<?php foreach ($items as $item): ?>
|
||||
fbq('track', 'AddToCart', {
|
||||
value: '<?php echo $item['item']->getPriceBrutto() ?>',
|
||||
currency: '<?php echo $currency ?>',
|
||||
content_name: 'shopping cart',
|
||||
content_type: 'product',
|
||||
|
||||
<?php if ($fbremarketingConfig['content_id'] == 'product_code'): ?>
|
||||
|
||||
content_ids: ['<?php echo $item['item']->getCode(); ?>']
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
content_ids: ['<?php echo $item['item']->getProduct()->getId(); ?>']
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
}, {eventID: '<?php echo $event_id ?>'});
|
||||
<?php endforeach ?>
|
||||
</script>
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
$smarty->assign('config_fbremarketing', $fbremarketingConfig);
|
||||
|
||||
if ($product_card == 1) {
|
||||
|
||||
$smarty->assign('product_card', $product_card);
|
||||
|
||||
$product_name = str_replace("'", '', $product->getName());
|
||||
|
||||
$smarty->assign('name', $product_name);
|
||||
|
||||
|
||||
if ($product->getDefaultCategory()) {
|
||||
|
||||
$category = str_replace("'", '', $product->getDefaultCategory()->getName());
|
||||
|
||||
$smarty->assign('category', $category);
|
||||
|
||||
} else {
|
||||
|
||||
$smarty->assign('category', "NONE");
|
||||
|
||||
}
|
||||
|
||||
if ($fbremarketingConfig['content_id'] == 'product_code'){
|
||||
$code = $product->getCode();
|
||||
} else{
|
||||
$code = $product->getid();
|
||||
}
|
||||
|
||||
$smarty->assign('code', $code);
|
||||
|
||||
$smarty->assign('price', $product->getPriceBrutto());
|
||||
|
||||
$smarty->assign('currency', $product->getCurrency());
|
||||
|
||||
|
||||
$event_id = sfContext::getInstance()->getUser()->getAttribute("fb_api_ViewContent");
|
||||
|
||||
if ($event_id=="") {
|
||||
$event_id = "0".mt_rand(100000, 999999);
|
||||
}
|
||||
|
||||
$smarty->assign('event_id', $event_id);
|
||||
|
||||
}
|
||||
|
||||
if ($orders == 1) {
|
||||
|
||||
$smarty->assign('orders', $orders);
|
||||
|
||||
$smarty->assign('value', $order->getTotalAmount(true));
|
||||
|
||||
$smarty->assign('currency', $order->getOrderCurrency()->getShortcut());
|
||||
|
||||
$row=array();
|
||||
|
||||
@$last_key = end(array_keys($order->getOrderProducts()));
|
||||
|
||||
$sum = 0;
|
||||
|
||||
foreach ($order->getOrderProducts() as $index => $order_products)
|
||||
{
|
||||
|
||||
|
||||
if ($index == $last_key)
|
||||
{
|
||||
|
||||
|
||||
if ($fbremarketingConfig['content_id'] == 'product_code'){
|
||||
$row[$index]['code']=$order_products->getCode();
|
||||
} else{
|
||||
$row[$index]['code']=$order_products->getProduct()->getId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
if ($fbremarketingConfig['content_id'] == 'product_code'){
|
||||
$row[$index]['code']=$order_products->getCode().', ';
|
||||
} else{
|
||||
$row[$index]['code']=$order_products->getProduct()->getId().', ';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$row[$index]['quantity']=$order_products->getQuantity();
|
||||
|
||||
$sum+= $row[$index]['quantity'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
$event_id = sfContext::getInstance()->getUser()->getAttribute("fb_api_Purchase");
|
||||
|
||||
|
||||
|
||||
if ($event_id=="") {
|
||||
$event_id = "0".mt_rand(100000, 999999);
|
||||
}
|
||||
|
||||
$smarty->assign('event_id', $event_id);
|
||||
|
||||
|
||||
$smarty->assign('num_items', $sum);
|
||||
|
||||
$smarty->assign('results',$row);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($basket == 1) {
|
||||
|
||||
$smarty->assign('basket', $basket);
|
||||
|
||||
$items = sfContext::getInstance()->getUser()->getBasket()->getItems();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$value = $item->getPriceBrutto();
|
||||
$content_ids = $item->getCode();
|
||||
|
||||
|
||||
if ($fbremarketingConfig['content_id'] == 'product_code'){
|
||||
$content_ids = $item->getCode();
|
||||
} else{
|
||||
$content_ids = $item->getProduct()->getId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$smarty->assign('currency', $currency);
|
||||
$smarty->assign('value', $value);
|
||||
|
||||
$smarty->assign('content_ids', $content_ids);
|
||||
|
||||
|
||||
$event_id = sfContext::getInstance()->getUser()->getAttribute("fb_api_InitiateCheckout");
|
||||
|
||||
|
||||
if ($event_id=="") {
|
||||
$event_id = "4".mt_rand(100000, 999999);
|
||||
}
|
||||
|
||||
$smarty->assign('event_id', $event_id);
|
||||
|
||||
}
|
||||
|
||||
$smarty->assign('lang', $lang);
|
||||
|
||||
$smarty->display('fbremarketing.html');
|
||||
@@ -0,0 +1,28 @@
|
||||
<script>
|
||||
{literal}
|
||||
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
|
||||
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
|
||||
n.push=n;n.loaded=!0;n.version='2.0';n.agent='plsote';n.queue=[];t=b.createElement(e);t.async=!0;
|
||||
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
|
||||
document,'script','https://connect.facebook.net/en_US/fbevents.js');
|
||||
fbq('init', '{/literal}{$config_fbremarketing.code_fbremarketing}{literal}');
|
||||
fbq('track', 'PageView');
|
||||
{/literal}{if $product_card == 1}{literal}fbq('track', 'ViewContent', {
|
||||
content_name: '{/literal}{$name}{literal}',
|
||||
content_category: '{/literal}{$category}{literal}',
|
||||
content_ids: ['{/literal}{$code}{literal}'],
|
||||
content_type: 'product',
|
||||
value: {/literal}{$price}{literal},
|
||||
currency: '{/literal}{$currency}{literal}'
|
||||
});{/literal}{elseif $orders == 1}{literal}fbq('track', 'Purchase', {
|
||||
value: '{/literal}{$value}{literal}',
|
||||
currency: '{/literal}{$currency}{literal}',
|
||||
content_name: 'order summary',
|
||||
content_type: 'product',
|
||||
content_ids: ['{/literal}{foreach key=row item=product from=$results}{$product.code}{/foreach}{literal}'],
|
||||
num_items: '{/literal}{$num_items}{literal}'
|
||||
});{/literal}
|
||||
{/if}
|
||||
|
||||
</script>
|
||||
<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={$config_fbremarketing.code_fbremarketing}&ev=PageView&noscript=1" /></noscript>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script>
|
||||
{literal}
|
||||
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
|
||||
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
|
||||
n.push=n;n.loaded=!0;n.version='2.0';n.agent='plsote';n.queue=[];t=b.createElement(e);t.async=!0;
|
||||
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
|
||||
document,'script','https://connect.facebook.net/en_US/fbevents.js');
|
||||
fbq('init', '{/literal}{$config_fbremarketing.code_fbremarketing}{literal}');
|
||||
fbq('track', 'PageView');
|
||||
{/literal}
|
||||
{if $product_card == 1}{literal}fbq('track', 'ViewContent', {
|
||||
content_name: '{/literal}{$name}{literal}',
|
||||
content_category: '{/literal}{$category}{literal}',
|
||||
content_ids: ['{/literal}{$code}{literal}'],
|
||||
content_type: 'product',
|
||||
value: {/literal}{$price}{literal},
|
||||
currency: '{/literal}{$currency}{literal}'
|
||||
},{eventID: '{/literal}{$event_id}{literal}'});{/literal}
|
||||
{elseif $orders == 1}{literal}fbq('track', 'Purchase', {
|
||||
value: '{/literal}{$value}{literal}',
|
||||
currency: '{/literal}{$currency}{literal}',
|
||||
content_name: 'order summary',
|
||||
content_type: 'product',
|
||||
content_ids: ['{/literal}{foreach key=row item=product from=$results}{$product.code}{/foreach}{literal}'],
|
||||
num_items: '{/literal}{$num_items}{literal}'
|
||||
},{eventID: '{/literal}{$event_id}{literal}'});{/literal}
|
||||
{elseif $basket == 1}{literal}fbq('track', 'InitiateCheckout', {
|
||||
value: '{/literal}{$value}{literal}',
|
||||
currency: '{/literal}{$currency}{literal}',
|
||||
content_name: 'checkout',
|
||||
content_type: 'product',
|
||||
content_ids: ['{/literal}{$content_ids}{literal}'],
|
||||
},{eventID: '{/literal}{$event_id}{literal}'});{/literal}
|
||||
{/if}
|
||||
|
||||
</script>
|
||||
<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={$config_fbremarketing.code_fbremarketing}&ev=PageView&noscript=1" /></noscript>
|
||||
Reference in New Issue
Block a user