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

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
fbshipit-source-id: 30fb28c32e25560f25cce85cf64e3b7b1e6e0c1b
  • Loading branch information
facebook-github-bot committed Nov 3, 2020
0 parents commit 580593d
Show file tree
Hide file tree
Showing 128 changed files with 45,925 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CODEOFCONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to.
Please read the [full text](https://code.fb.com/codeofconduct/)
so that you can understand what actions will and will not be tolerated.
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Contributing to Facebook Business Extension For Magento2
We want to make contributing to this project as easy and transparent as
possible.

## Pull Requests
We actively welcome your pull requests.

1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Make sure your code lints.
5. If you haven't already, complete the Contributor License Agreement ("CLA").

## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Facebook's open source projects.

Complete your CLA here: <https://code.facebook.com/cla>

## Issues
We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.

Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.

## Coding Style
* 4 spaces for indentation rather than tabs
* 80 character line length

## License
By contributing to Facebook Business Extension For Magento2, you agree that your contributions
will be licensed under the LICENSE file in the root directory of
this source tree.
22 changes: 22 additions & 0 deletions Facebook/BusinessExtension/Block/Adminhtml/Common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/

namespace Facebook\BusinessExtension\Block\Adminhtml;

class Common extends \Magento\Backend\Block\Template {

protected $_registry;
protected $_fbeHelper;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Facebook\BusinessExtension\Helper\FBEHelper $fbeHelper,
array $data = []) {
$this->_registry = $registry;
$this->_fbeHelper = $fbeHelper;
parent::__construct($context, $data);
}
}
57 changes: 57 additions & 0 deletions Facebook/BusinessExtension/Block/Adminhtml/Setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/

namespace Facebook\BusinessExtension\Block\Adminhtml;

class Setup extends Common {

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Facebook\BusinessExtension\Helper\FBEHelper $fbeHelper,
array $data = []) {
parent::__construct($context, $registry, $fbeHelper, $data);
}

public function getPixelAjaxRoute() {
return $this->_fbeHelper->getUrl('fbeadmin/ajax/fbpixel');
}

public function getAccessTokenAjaxRoute() {
return $this->_fbeHelper->getUrl('fbeadmin/ajax/fbtoken');
}

public function getProfilesAjaxRoute() {
return $this->_fbeHelper->getUrl('fbeadmin/ajax/fbprofiles');
}

public function getAAMSettingsRoute(){
return $this->_fbeHelper->getUrl('fbeadmin/ajax/fbaamsettings');
}

public function fetchPixelId() {
return $this->_fbeHelper->getConfigValue('fbpixel/id');
}

public function getExternalBusinessId() {
return $this->_fbeHelper->getFBEExternalBusinessId();
}

public function getFeedPushAjaxRoute() {
return $this->_fbeHelper->getUrl('fbeadmin/ajax/fbfeedpush');
}

public function getDeleteAssetIdsAjaxRoute() {
return $this->_fbeHelper->getUrl('fbeadmin/ajax/fbdeleteasset');
}

public function getCurrencyCode() {
return $this->_fbeHelper->getStoreCurrencyCode();
}

public function isFBEInstalled() {
return $this->_fbeHelper->isFBEInstalled();
}
}
14 changes: 14 additions & 0 deletions Facebook/BusinessExtension/Block/Pixel/AddToCart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/

namespace Facebook\BusinessExtension\Block\Pixel;

class AddToCart extends Common {

public function getProductInfoUrl() {
return sprintf('%sfbe/Pixel/ProductInfoForAddToCart', $this->_fbeHelper->getBaseUrl());
}

}
130 changes: 130 additions & 0 deletions Facebook/BusinessExtension/Block/Pixel/Common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/

namespace Facebook\BusinessExtension\Block\Pixel;

use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\ObjectManagerInterface;
use \Facebook\BusinessExtension\Helper\AAMSettingsFields;

class Common extends \Magento\Framework\View\Element\Template {
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $_objectManager;
protected $_registry;
protected $_fbeHelper;
protected $_magentoDataHelper;

public function __construct(
Context $context,
ObjectManagerInterface $objectManager,
\Magento\Framework\Registry $registry,
\Facebook\BusinessExtension\Helper\FBEHelper $fbeHelper,
\Facebook\BusinessExtension\Helper\MagentoDataHelper $magentoDataHelper,
array $data = []) {
parent::__construct($context, $data);
$this->_objectManager = $objectManager;
$this->_registry = $registry;
$this->_fbeHelper = $fbeHelper;
$this->_magentoDataHelper = $magentoDataHelper;
}

public function arrayToCommaSeperatedStringValues($a) {
return implode(',', array_map(function ($i) { return '"'.$i.'"'; }, $a));
}

public function escapeQuotes($string) {
return addslashes($string);
}

public function getFacebookPixelID() {
return $this->_fbeHelper->getPixelID();
}

public function getPixelInitCode(){
$aamSettings = $this->_fbeHelper->getAAMSettings();
$customer = $this->_magentoDataHelper->getCurrentCustomer();
if($customer && $aamSettings && $aamSettings->getEnableAutomaticMatching()){
try{
$address = $this->_magentoDataHelper->getCustomerAddress($customer);
$userInfo = array();
if(in_array(AAMSettingsFields::EMAIL, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['em'] = $customer->getEmail();
}
if(in_array(AAMSettingsFields::FIRST_NAME, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['fn'] = $customer->getFirstname();
}
if(in_array(AAMSettingsFields::LAST_NAME, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['ln'] = $customer->getLastname();
}
if(in_array(AAMSettingsFields::GENDER, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['ge'] = $this->_magentoDataHelper->getGenderAsString($customer);
}
if(in_array(AAMSettingsFields::DATE_OF_BIRTH, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['db'] = $customer->getDob() ? date("Ymd", strtotime($customer->getDob())) : null;
}
if($address){
if(in_array(AAMSettingsFields::PHONE, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['ph'] = $address->getTelephone();
}
if(in_array(AAMSettingsFields::CITY, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['ct'] = $address->getCity();
}
if(in_array(AAMSettingsFields::STATE, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['st'] = $this->_magentoDataHelper->getRegionCodeForAddress($address);
}
if(in_array(AAMSettingsFields::ZIP_CODE, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['zp'] = $address->getPostcode();
}
if(in_array(AAMSettingsFields::COUNTRY, $aamSettings->getEnabledAutomaticMatchingFields())){
$userInfo['cn'] = $address->getCountryId(); //Added for upward compatibility
}
}
return json_encode(array_filter($userInfo), JSON_PRETTY_PRINT | JSON_FORCE_OBJECT);
}
catch(Exception $e) {
$this->fbeHelper->logException($e);
}
}
return '{}';
}

public function getSource() {
return $this->_fbeHelper->getSource();
}

public function getMagentoVersion() {
return $this->_fbeHelper->getMagentoVersion();
}

public function getPluginVersion() {
return $this->_fbeHelper->getPluginVersion();
}

public function getFacebookAgentVersion() {
return $this->_fbeHelper->getPartnerAgent();
}

public function getContentType() {
return 'product';
}

public function getCurrency() {
return $this->_storeManager->getStore()->getCurrentCurrency()->getCode();
}

public function logEvent($pixel_id, $pixel_event) {
$this->_fbeHelper->logPixelEvent($pixel_id, $pixel_event);
}

public function getEventToObserveName(){
return '';
}

public function trackServerEvent($eventId){
$this->_eventManager->dispatch($this->getEventToObserveName(), ['eventId' => $eventId]);
}
}
28 changes: 28 additions & 0 deletions Facebook/BusinessExtension/Block/Pixel/Head.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/

namespace Facebook\BusinessExtension\Block\Pixel;

class Head extends Common {
/**
* Create JS code with the data processing options if required
* To learn about this options in Facebook Pixel, read:
* https://developers.facebook.com/docs/marketing-apis/data-processing-options
* @return string
*/
public function getDataProcessingOptionsJSCode(){
return "";
}

/**
* Create the data processing options passed in the Pixel image tag
* Read about this options in:
* https://developers.facebook.com/docs/marketing-apis/data-processing-options
* @return string
*/
public function getDataProcessingOptionsImgTag(){
return "";
}
}
70 changes: 70 additions & 0 deletions Facebook/BusinessExtension/Block/Pixel/InitiateCheckout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/

namespace Facebook\BusinessExtension\Block\Pixel;

class InitiateCheckout extends Common {

public function getContentIDs() {
$product_ids = array();
$cart = $this->_fbeHelper->getObject('\Magento\Checkout\Model\Cart');
$items = $cart->getQuote()->getAllVisibleItems();
$product_model = $this->_fbeHelper->getObject('\Magento\Catalog\Model\Product');
foreach ($items as $item) {
$product = $product_model->load($item->getProductId());
$product_ids[] = $product->getId();
}
return $this->arrayToCommaSeperatedStringValues($product_ids);
}

public function getValue() {
$cart = $this->_fbeHelper->getObject('\Magento\Checkout\Model\Cart');
if(!$cart || !$cart->getQuote()) {
return null;
}
$subtotal = $cart->getQuote()->getSubtotal();
if ($subtotal) {
$price_helper = $this->_fbeHelper->getObject('Magento\Framework\Pricing\Helper\Data');
return $price_helper->currency($subtotal, false, false);
} else {
return null;
}
}

public function getContents() {
$cart = $this->_fbeHelper->getObject('\Magento\Checkout\Model\Cart');
if(!$cart || !$cart->getQuote()) {
return '';
}
$contents = array();
$items = $cart->getQuote()->getAllVisibleItems();
$product_model = $this->_fbeHelper->getObject('\Magento\Catalog\Model\Product');
$priceHelper = $this->_objectManager->get('Magento\Framework\Pricing\Helper\Data');
foreach ($items as $item) {
$product = $product_model->load($item->getProductId());
$price = $priceHelper->currency($product->getFinalPrice(), false, false);
$content = '{id:"'.$product->getId().'",quantity:'.intval($item->getQty()).',item_price:'.$price."}";
$contents[] = $content;
}
return implode(',', $contents );
}

public function getNumItems() {
$cart = $this->_fbeHelper->getObject('\Magento\Checkout\Model\Cart');
if(!$cart || !$cart->getQuote()) {
return null;
}
$numItems = 0;
$items = $cart->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
$numItems += $item->getQty();
}
return $numItems;
}

public function getEventToObserveName(){
return 'facebook_businessextension_ssapi_initiate_checkout';
}
}
Loading

0 comments on commit 580593d

Please sign in to comment.