FacebookCheckout.php in Facebook Pixel 8
File
modules/facebook_pixel_commerce/src/Plugin/Commerce/CheckoutPane/FacebookCheckout.php
View source
<?php
namespace Drupal\facebook_pixel_commerce\Plugin\Commerce\CheckoutPane;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\facebook_pixel\FacebookEventInterface;
use Drupal\facebook_pixel_commerce\FacebookCommerceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FacebookCheckout extends CheckoutPaneBase {
protected $facebookEvent;
protected $facebookComment;
public function __construct(array $configuration, $plugin_id, $plugin_definition, CheckoutFlowInterface $checkout_flow, EntityTypeManagerInterface $entity_type_manager, FacebookEventInterface $facebook_event, FacebookCommerceInterface $facebook_comment) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $checkout_flow, $entity_type_manager);
$this->facebookEvent = $facebook_event;
$this->facebookComment = $facebook_comment;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, CheckoutFlowInterface $checkout_flow = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $checkout_flow, $container
->get('entity_type.manager'), $container
->get('facebook_pixel.facebook_event'), $container
->get('facebook_pixel_commerce.facebook_commerce'));
}
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
if (!$form_state
->getTriggeringElement()) {
$data = $this->facebookComment
->getOrderData($this->order);
$this->facebookEvent
->addEvent('InitiateCheckout', $data);
}
return [];
}
}