public function ProductHandler::getProductVariant in Mailchimp E-Commerce 8
@inheritdoc
Overrides ProductHandlerInterface::getProductVariant
File
- src/
ProductHandler.php, line 135
Class
- ProductHandler
- Product handler.
Namespace
Drupal\mailchimp_ecommerceCode
public function getProductVariant($product_id, $product_variant_id) {
$product_variant = NULL;
try {
$store_id = mailchimp_ecommerce_get_store_id();
if (empty($store_id)) {
throw new \Exception('Cannot get a product variant without a store ID.');
}
/* @var \Mailchimp\MailchimpEcommerce $mc_ecommerce */
$mc_ecommerce = mailchimp_get_api_object('MailchimpEcommerce');
$product_variant = $mc_ecommerce
->getProductVariant($store_id, $product_id, $product_variant_id);
// Mailchimp will return a product variant object even if the variant
// doesn't exist. Checking for an empty SKU is a reliable way to
// determine if a product variant doesn't exist in Mailchimp.
if (empty($product_variant->sku)) {
return NULL;
}
} catch (\Exception $e) {
mailchimp_ecommerce_log_error_message('Unable to get product variant: ' . $e
->getMessage());
drupal_set_message($e
->getMessage(), 'error');
}
return $product_variant;
}