public function setStatusForProduct(ProductInterface $product, $statusId)
    {
        // Check if status has changed.
        if ($product->getStatus() && $product->getStatus()->getId() === $statusId) {
            return;
        }

        $status = $this->statusRepository->find($statusId);
        if (!$status) {
            throw new ProductDependencyNotFoundException(self::$productStatusEntityName, $statusId);
        }

        // Set new status to product.
        $product->setStatus($status);

        // If product has variants, set status for all variants as well.
        if ($product->getType()
            && $product->getType()->getId() === (int) $this->productTypesMap['PRODUCT_WITH_VARIANTS']
        ) {
            $variants = $this->productRepository->findByParent($product);
            foreach ($variants as $variant) {
                $variant->setStatus($status);
            }
        }
    }