public function FacebookCommerce::getOrderData in Facebook Pixel 8
Build the Facebook object for orders.
Parameters
\Drupal\commerce_order\Entity\OrderInterface $order: The order object.
Return value
array The data array for an order.
Overrides FacebookCommerceInterface::getOrderData
File
- modules/
facebook_pixel_commerce/ src/ FacebookCommerce.php, line 43
Class
- FacebookCommerce
- Helper methods for facebook_pixel_commerce module.
Namespace
Drupal\facebook_pixel_commerceCode
public function getOrderData(OrderInterface $order) {
$contents = [];
$content_ids = [];
$data = [
'value' => $this->rounder
->round($order
->getTotalPrice())
->getNumber(),
'currency' => $order
->getTotalPrice()
->getCurrencyCode(),
'num_items' => count($order
->getItems()),
'content_name' => 'order',
'content_type' => 'product',
];
foreach ($order
->getItems() as $order_item) {
$item_data = $this
->getOrderItemData($order_item);
if (!empty($item_data['contents'][0])) {
$contents[] = $item_data['contents'][0];
$content_ids[] = $item_data['contents'][0]['id'];
}
}
if (!empty($contents)) {
$data['contents'] = $contents;
$data['content_ids'] = $content_ids;
}
return $data;
}