You are here

function ProductHandler::buildProductFromNode in Mailchimp E-Commerce 8

Build Mailchimp product values from an Ubercart product node.

Parameters

Node $node: The Ubercart 'product' type node.

Return value

array Array of product values for use with Mailchimp.

File

src/ProductHandler.php, line 293

Class

ProductHandler
Product handler.

Namespace

Drupal\mailchimp_ecommerce

Code

function buildProductFromNode(Node $node) {
  $url = $this
    ->buildNodeUrl($node);
  $image_url = $this
    ->getNodeImageUrl($node);
  $variant = [
    'id' => $node
      ->id(),
    'title' => $node
      ->getTitle(),
    'url' => $url,
    'image_url' => $image_url,
    'sku' => $node->model->value,
    'price' => $node->price->value,
  ];
  $product = array(
    'id' => $node
      ->id(),
    'variant_id' => $node
      ->id(),
    'sku' => $node->model->value,
    'title' => $node
      ->getTitle(),
    'url' => $url,
    'image_url' => $image_url,
    'description' => $node->body->value,
    'price' => $node->price->value,
    'type' => $node
      ->getType(),
    'variants' => [
      $variant,
    ],
  );
  return $product;
}