You are here

public function ProductHandler::deleteProduct in Mailchimp E-Commerce 8

@inheritdoc

Overrides ProductHandlerInterface::deleteProduct

File

src/ProductHandler.php, line 87

Class

ProductHandler
Product handler.

Namespace

Drupal\mailchimp_ecommerce

Code

public function deleteProduct($product_id) {
  try {
    $store_id = mailchimp_ecommerce_get_store_id();
    if (empty($store_id)) {
      throw new \Exception('Cannot delete a product without a store ID.');
    }

    /* @var \Mailchimp\MailchimpEcommerce $mc_ecommerce */
    $mc_ecommerce = mailchimp_get_api_object('MailchimpEcommerce');
    $mc_ecommerce
      ->deleteProduct($store_id, $product_id);
  } catch (\Exception $e) {
    mailchimp_ecommerce_log_error_message('Unable to delete product: ' . $e
      ->getMessage());
    drupal_set_message($e
      ->getMessage(), 'error');
  }
}