0

I have a site where I created a custom page to list products (can't use views module due to custom requirements for printing that list). On the list page for each product I have variation sku available. I want to show add to cart form with qty field on this custom list page. I have searched for a solution but couldn't find one for drupal 8. I know how to do it in drupal 7 but can someone help me with how we can have this in D8?

0

I got solution to the above problem. I used a drupal commerce service to load the form. Below is the code which I used, please let me know if it is an acceptable solution.

$commerceProduct = \Drupal::service('commerce_product.lazy_builders');
$cart_array = $commerceProduct->addToCartForm($product_id, 'teaser', true, $language);

This gave me a renderable array which I rendered using render service. Add to cart form is working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.