first commit

This commit is contained in:
2025-03-12 17:06:23 +01:00
commit 2241f7131f
13185 changed files with 1692479 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
<?php
/**
* SOTESHOP/appFacebookRemarketingPlugin
*
*
* @package appFacebookRemarketingPlugin
* @author Pawel Byszewski <pawel@apes-apps.com>
*/
class appFacebookRemarketingBackendActions extends stAdminGeneratorActions
{
public function initializeParameters()
{
$this->webRequest = new stWebRequest();
$this->config = stConfig::getInstance('appFacebookRemarketingBackend');
if ($this->config->get('code_fbremarketing', $this->getRequestParameter('fbremarketing[code_fbremarketing]'), true) == '') {
$notice = '<a href="https://pl-pl.facebook.com/ads/manager/pixel/custom_audience_pixel/" target="_blank">'.$this->getContext()->getI18n()->__('Utwórz piksel').'</a>'."&nbsp;".$this->getContext()->getI18n()->__(' w menedżerze reklam Facebook.');
$this->setFlash("info", $notice, false);
$this->configuration_check = true;
} else {
$this->configuration_check = false;
}
$i18n = $this->getContext()->getI18n();
$this->labels = array(
'fbremarketing{code_fbremarketing}' => $i18n->__('Podaj indentyfikator piksela Facebooka'),
);
}
public function executeIndex()
{
$this->initializeParameters();
$i18n = $this->getContext()->getI18N();
$this->config = stConfig::getInstance('appFacebookRemarketingBackend');
$this->config->setCulture($this->getRequestParameter('culture', stLanguage::getOptLanguage()));
if ($this->getRequest()->getMethod() == sfRequest::POST)
{
$this->config->set('enable_fbremarketing', $this->getRequestParameter('fbremarketing[enable_fbremarketing]'));
$this->config->set('content_id', $this->getRequestParameter('fbremarketing[content_id]'));
$this->config->set('code_fbremarketing', $this->getRequestParameter('fbremarketing[code_fbremarketing]'), true);
$this->config->set('product_card', $this->getRequestParameter('fbremarketing[product_card]'));
$this->config->set('cart', $this->getRequestParameter('fbremarketing[cart]'));
$this->config->set('basket', $this->getRequestParameter('fbremarketing[basket]'));
$this->config->set('order', $this->getRequestParameter('fbremarketing[order]'));
if ($this->config->get('enable_fbremarketing') && $this->config->get('code_fbremarketing', null, true))
{
stAppStats::activate('Piksel Facebooka');
}
else
{
stAppStats::deactivate('Piksel Facebooka');
}
$this->config->save();
stFastCacheManager::clearCache();
$this->setFlash('notice', $i18n->__('Twoje zmiany zostały zapisane', null, 'stAdminGeneratorPlugin'));
$this->redirect('appFacebookRemarketingBackend/index?culture=' . $this->getRequestParameter('culture', stLanguage::getOptLanguage()));
}
$this->config->load();
$this->getBreadcrumbs()->add($i18n->__('Konfiguracja', null, 'stAdminGeneratorPlugin'));
}
public function validateIndex()
{
if ($this->getRequest()->getMethod() == sfRequest::POST)
stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName());
return true;
}
public function handleErrorIndex()
{
$this->initializeParameters();
$i18n = $this->getContext()->getI18N();
$this->getBreadcrumbs()->add($i18n->__('Konfiguracja', null, 'stAdminGeneratorPlugin'));
return sfView::SUCCESS;
}
protected function getBreadcrumbs(){
if (null === $this->breadcrumbs){
$i18n = $this->getContext()->getI18N();
$this->breadcrumbs = parent::getBreadcrumbs();
$this->breadcrumbs->add($i18n->__('Piksel Facebooka'), '@appFacebookRemarketingPlugin');
}
return $this->breadcrumbs;
}
}

View File

@@ -0,0 +1,13 @@
<?php
class appFacebookRemarketingBackendComponents extends sfComponents
{
public function executeListMenu()
{
}
}
?>

View File

@@ -0,0 +1,17 @@
<div class="list-menu">
<ul>
<li class="selected">
<?php echo link_to(__('Konfiguracja'),'appFacebookRemarketingBackend/index')?>
</li>
<li>
<?php if (sfContext::getInstance()->getUser()->getCulture() == 'pl_PL'): ?>
<a href="https://www.sote.pl/docs/piksel-facebooka" target="_blank"><?php echo __('Dokumentacja'); ?></a>
<?php else : ?>
<a href="https://www.soteshop.com/docs/facebook_pixel" target="_blank"><?php echo __('Documentation'); ?></a>
<?php endif; ?>
</li>
</ul>
</div>
<div class="clr"></div>

View File

@@ -0,0 +1,74 @@
<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date', 'VisualEffect', 'stAdminGenerator') ?>
<?php st_view_slot_start('application-menu') ?>
<?php st_include_component('appFacebookRemarketingBackend', 'listMenu') ?>
<?php st_view_slot_end() ?>
<?php echo st_get_admin_head(array('@appFacebookRemarketingBackend', __('Piksel Facebooka'), 'appFacebookRemarketingPlugin.svg'), __('Piksel Facebooka')) ?>
<?php st_include_partial('stAdminGenerator/message', array('labels' => $labels)); ?>
<?php echo form_tag('appFacebookRemarketingBackend/index?culture='.$config->getCulture(), array('id' => 'sf_admin_config_form', 'name' => 'sf_admin_config_form', 'class' => 'admin_form')) ?>
<fieldset>
<div class="content">
<div class="form-row">
<?php echo st_admin_get_form_field('fbremarketing[enable_fbremarketing]', __('Włącz'), true, 'checkbox_tag', array('checked' => $config->get('enable_fbremarketing'))); ?>
</div>
<div class="form-row">
<?php echo st_admin_get_form_field('fbremarketing[code_fbremarketing]', __('Identyfikator Piksela Facebooka'), $config->get('code_fbremarketing', null, true), 'input_tag', array('required' => true, 'autocomplete' => "off", 'help' => __('Identyfikator można znaleźć przy pikselu w panelu Facebook. Identyfikator występuje też w kodzie piksela. Jest to ciąg cyfr.'))) ?>
</div>
<div class="row">
<?php echo label_for('fbremarketing[content_id]', __('Identyfikacja produktu')) ?>
<div class="field">
<?php echo select_tag('fbremarketing[content_id]', options_for_select(array('product_code' => __('Po kodzie produktu'), 'product_id' => __('Po ID produktu')), $config->get('content_id')), array('help' => __('Warość pola: content_id'))); ?>
<br class="st_clear_all" />
</div>
</div>
</div>
</fieldset>
<fieldset>
<h2><?php echo __('Rejestrowanie zdarzeń');?></h2>
<div class="content">
<div class="form-row">
<?php echo st_admin_get_form_field('fbremarketing[product_card]', __('Wyświetlanie produktu'), true, 'checkbox_tag', array('checked' => $config->get('product_card'), 'help' =>__('Akcja: ViewContent'))); ?>
</div>
<div class="form-row">
<?php echo st_admin_get_form_field('fbremarketing[cart]', __('Dodanie do koszyka'), true, 'checkbox_tag', array('checked' => $config->get('cart'), 'help' =>__('Akcja: AddToCart'))); ?>
</div>
<div class="form-row">
<?php echo st_admin_get_form_field('fbremarketing[basket]', __('Rozpoczęcie realizacji zamówienia'), true, 'checkbox_tag', array('checked' => $config->get('basket'), 'help' =>__('Akcja: InitiateCheckout'))); ?>
</div>
<div class="form-row">
<?php echo st_admin_get_form_field('fbremarketing[order]', __('Rozpoczęcie realizacji zamówienia'), true, 'checkbox_tag', array('checked' => $config->get('order'), 'help' =>__('Akcja: Purchase'))); ?>
</div>
</div>
</fieldset>
<div id="config_actions">
<?php echo st_get_admin_actions_head() ?>
<?php echo st_get_admin_action('save', __('Zapisz', null, 'stAdminGeneratorPlugin'), null, array('name' => 'save')) ?>
<?php echo st_get_admin_actions_foot() ?>
</div>
</form>
<?php echo st_get_admin_foot() ?>
<script type="text/javascript">
jQuery(function($) {
$(document).ready(function() {
$('#config_actions').stickyBox();
fieldsetVisibility();
});
});
</script>

View File

@@ -0,0 +1,4 @@
fields:
fbremarketing{code_fbremarketing}:
required:
msg: Proszę uzupełnić pole.

View File

@@ -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();
}
}

View File

@@ -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>

View File

@@ -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');

View File

@@ -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>

View File

@@ -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>