# Summary

Provides an "add to cart" confirmation dialog, shown after the customer has added a product to his cart. Adds an "add to cart confirmation" view mode to commerce_product entities, and uses it to show the newly added product in the confirmation dialog.

# Project URL

https://www.drupal.org/project/commerce_add_to_cart_confirmation

# Where is the code?

Developing is in progress

# Estimated completion date

Unknown

# Dependencies

Unknown

# Who's doing the port?

Unknown

# What help do they need?

Unknown

# D8 roadmap

Unknown

# Background and reference information

Unknown

Comments

legaudinier created an issue. See original summary.

bojanz’s picture

Anyone deciding to port this module: I think relying on https://awkward.github.io/backbone.modal/ is probably the best option.

iyyappan.govind’s picture

Assigned: Unassigned » iyyappan.govind
Issue summary: View changes
niko-’s picture

bojanz’s picture

@niko-
Thanks! I'd be happy to give you commit access.

Let's fix the following first:
- commerce_add_to_cart_confirmation.html.twig -> has untranslated strings (not run through |t)
- CommerceAddToCartConfirmationMessage has a PHPstorm generated docblock, remove it. Event subscribers should be suffixed with Subscriber. Commerce is a redundant prefix. Suggested new name: ConfirmationMessageSubscriber.
- The event subscriber uses the order item matcher for no reason, the passed event already contains the destination order item.
- commerce_add_to_cart_confirmation.module has a hook with no docblock, and is missing a proper @file docblock instead of the phpstorm one.
- The shipped config should not contain UUIDs (currently on line 1 of each YAML
- commerce_add_to_cart_confirmation.js has a cyrilic comment.

Would also be great to get a screenshot.

niko-’s picture

Hi @bojanz

Thanks for your reply and happy New Year and Merry Christmas

About
- The event subscriber uses the order item matcher for no reason, the passed event already contains the destination order item.

For your understanding why I have used order item matcher please check \Drupal\commerce_cart\CartManager::addOrderItem.

  /**
   * {@inheritdoc}
   */
  public function addOrderItem(OrderInterface $cart, OrderItemInterface $order_item, $combine = TRUE, $save_cart = TRUE) {
    $purchased_entity = $order_item->getPurchasedEntity();
    $quantity = $order_item->getQuantity();
    $matching_order_item = NULL;
    if ($combine) {
      $matching_order_item = $this->orderItemMatcher->match($order_item, $cart->getItems());
    }
    if ($matching_order_item) {
      $new_quantity = Calculator::add($matching_order_item->getQuantity(), $quantity);
      $matching_order_item->setQuantity($new_quantity);
      $matching_order_item->save();
    }
    else {
      $order_item->save();
      $cart->addItem($order_item);
    }

    $event = new CartEntityAddEvent($cart, $purchased_entity, $quantity, $order_item);
    $this->eventDispatcher->dispatch(CartEvents::CART_ENTITY_ADD, $event);
    if ($save_cart) {
      $cart->save();
    }

    return $order_item;
  }

As you see CartEntityAddEvent event calls only if $order_item is not availible in the cart. So if user add some product to cart twice (1 quantity on first add to cart and 1 for the second add to cart ) event will call only for first one. Not sure that this is Ok and how we should manage this situation.

If the $combine seted to TRUE I think we must call event like this

    $event = new CartEntityAddEvent($cart, $purchased_entity, $quantity, $matching_order_item);

but now it calls with "empty" $order_item

bojanz’s picture

niko-’s picture

Also https://www.drupal.org/node/2638958#comment-11848499 is blocker for normal implementation for this module.

bojanz’s picture

@niko-
That issue is about Views relationships, your problem is about view modes, you'll need to open a new bug report.

niko-’s picture

Here is bug about view modes https://www.drupal.org/node/2840386

niko-’s picture

Repo on github was updated according to #5 except #8 also theming is in progress now

niko-’s picture

initial css pushed to repo see screanshort http://prntscr.com/dqnxj5
we need fix this https://www.drupal.org/node/2840386 to fianlize cssing

niko-’s picture

Github repo was updated latest changes.
1. OrderOtherCount views area
2. OrderItemOrderTotal views area
3. multiple minor fixes

iyyappan.govind’s picture

Assigned: iyyappan.govind » Unassigned
init90’s picture

Thanks all for work here! I've started using the module and added some improvements and fixes: https://github.com/init90/commerce_add_to_cart_confirmation

I think it ready for the dev release and will be good if someone can help with it.
Also, I can help maintain the module.

bojanz’s picture

Sure!

@niko-
Looks like I never granted you access. Would you like to co-maintain with init90?

niko-’s picture

@bojanz Yep sure I can co-maintain

bojanz’s picture

Okay, both init90 and niko- now have access.

init90’s picture

Thanks @bojanz!

init90’s picture

I've added alpha release for the module.