You are here

public function ProductEventSubscriber::productUpdate in Mailchimp E-Commerce 8

Respond to event fired after updating an existing product.

File

modules/mailchimp_ecommerce_commerce/src/EventSubscriber/ProductEventSubscriber.php, line 57

Class

ProductEventSubscriber
Event Subscriber for Commerce Products.

Namespace

Drupal\mailchimp_ecommerce_commerce\EventSubscriber

Code

public function productUpdate(ProductEvent $event) {
  $product = $event
    ->getProduct();
  $title = !empty($product
    ->get('title')->value) ? $product
    ->get('title')->value : '';
  $description = !empty($product
    ->get('body')->value) ? $product
    ->get('body')->value : '';

  // TODO Fix Type
  $type = !empty($product
    ->get('type')->value) ? $product
    ->get('type')->value : '';
  $variants = $this->product_handler
    ->buildProductVariants($product);
  $url = $this->product_handler
    ->buildProductUrl($product);
  $image_url = $this->product_handler
    ->getProductImageUrl($product);

  // Update the existing product and variant.
  $this->product_handler
    ->updateProduct($product, $title, $url, $image_url, $description, $type, $variants);
}