Commit e56693bc authored by zqnlhvea's avatar zqnlhvea

init

parents
name: Commerce add to cart confirmation
type: module
description: 'Provide popup window for add to cart link.'
package: Commerce
core: 8.x
dependencies:
- commerce_cart
- commerce_product
- views
commerce_add_to_cart_confirmation:
version: VERSION
js:
js/commerce_add_to_cart_confirmation.js: {}
css:
theme:
css/commerce_add_to_cart_confirmation.css: {}
dependencies:
- core/jquery
- core/jquery.form
- core/drupal
- core/drupal.form
- core/drupal.ajax
- core/drupalSettings
- core/drupal.dialog
<?php
/**
* @file
* Main file for Commerce add to cart confirmation module.
*/
/**
* Implements hook_page_attachments().
*/
function commerce_add_to_cart_confirmation_page_attachments(array &$attachments) {
if (\Drupal::messenger()
->messagesByType('commerce-add-to-cart-confirmation')) {
$attachments['#attached']['library'][] = 'commerce_add_to_cart_confirmation/commerce_add_to_cart_confirmation';
}
}
\ No newline at end of file
services:
commerce_add_to_cart_confirmation_subscriber:
class: \Drupal\commerce_add_to_cart_confirmation\EventSubscriber\AddToCartConfirmationSubscriber
arguments:
- '@messenger'
tags:
- { name: event_subscriber }
/**
* Add to cart сщташкьфешщт.
*/
.messages.messages--commerce-add-to-cart-confirmation {
display: none;
padding: 0;
}
.commerce-add-to-cart-confirmation .ui-dialog-titlebar {
display: none;
}
.view-commerce-add-to-cart-confirmation {
display:flex;
flex-direction: row;
justify-content: flex-start;
height: 100%;
}
.view-commerce-add-to-cart-confirmation .view-content {
width: 65%;
padding: 15px;
}
.view-commerce-add-to-cart-confirmation .view-content .views-field-title {
margin-bottom: 15px;
font-size: 18px;
}
.view-commerce-add-to-cart-confirmation .view-content .views-field-price__currency-code {
color: #aeaaa5;
margin-top: 15px;
}
.view-commerce-add-to-cart-confirmation .view-content .views-field-title a{
color: #5c8e29;
}
.view-commerce-add-to-cart-confirmation .view-footer {
background-color: #e4eef3;
width: 35%;
}
.view-commerce-add-to-cart-confirmation .btn-wrapper {
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 30px;
position: relative;
}
.view-commerce-add-to-cart-confirmation .btn-wrapper .btn {
border-radius: 3px;
color: white;
font-weight: bold;
margin-bottom: 10px;
padding: 10px;
text-align: center;
min-width: 110px;
font-size: 16px;
}
.view-commerce-add-to-cart-confirmation .btn-wrapper .btn a,
.view-commerce-add-to-cart-confirmation .btn-wrapper .btn span {
color: #fff !important;
text-shadow: none !important;
text-decoration: none !important;
cursor: pointer;
}
.view-commerce-add-to-cart-confirmation .btn-wrapper .btn.checkout {
background-color: #5c8e29;
}
.view-commerce-add-to-cart-confirmation .btn-wrapper .btn.continue {
background-color: #b3b3b3;
}
.view-commerce-add-to-cart-confirmation .btn-wrapper .btn-close a {
background: url("../img/btn_add-to-cart-close.png") no-repeat 0 0;
display: block;
height: 17px;
position: absolute;
right: 10px;
top: 10px;
width: 18px;
}
.view-commerce-add-to-cart-confirmation .added-product-title {
color: #5c8e29;
font-size: 14px;
font-weight: bold;
padding: 0 30px 10px 20px;
text-align: center;
text-transform: uppercase;
}
(function ($, Drupal) {
'use strict';
Drupal.behaviors.commerce_add_to_cart_confirmation = {
attach: function (context) {
var popup_content = $('.messages--commerce-add-to-cart-confirmation', context).clone();
$('.messages--commerce-add-to-cart-confirmation').remove();
if (popup_content.length > 0) {
var confirmationModal = Drupal.dialog(popup_content, {
dialogClass: 'commerce-add-to-cart-confirmation',
width: 550,
height: 'auto',
maxWidth: '95%',
autoResize: true,
resizable: false,
resetSize: true,
close: function (event) {
$(event.target).remove();
}
});
confirmationModal.showModal();
$('.commerce-add-to-cart-confirmation-close').on('click', function () {
$('.commerce-add-to-cart-confirmation .ui-dialog-titlebar-close').trigger('click');
});
}
}
}
})(jQuery, Drupal);
<?php
namespace Drupal\commerce_add_to_cart_confirmation\EventSubscriber;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\Markup;
use Drupal\views\Views;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\commerce_cart\Event\CartEntityAddEvent;
use Drupal\commerce_cart\Event\CartEvents;
/**
* Event subscriber to display a popup when product is added to cart.
*/
class AddToCartConfirmationSubscriber implements EventSubscriberInterface {
/**
* The messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Constructor.
*
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* Messenger.
*/
public function __construct(MessengerInterface $messenger) {
$this->messenger = $messenger;
}
/**
* Initializes the purchased entity.
*
* @param \Drupal\commerce_cart\Event\CartEntityAddEvent $event
* The add to cart event.
*/
public function onAddToCartEvent(CartEntityAddEvent $event) {
$purchaced_entity = $event->getEntity();
$view = Views::getView('commerce_add_to_cart_confirmation');
$view->setDisplay('default');
$view->setArguments([$purchaced_entity->id()]);
$elements = $view->render();
$message = \Drupal::service('renderer')->render($elements);
$content = Markup::create($message);
$this->messenger->addMessage($content, 'commerce-add-to-cart-confirmation');
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
CartEvents::CART_ENTITY_ADD => 'onAddToCartEvent',
];
}
}
{#
/**
* @file
* Profile ws custom block.
*/
#}
<div class="confirmation-wrapper">
<div class="confirmation-wrapper__content">
<h1>{{ title }}</h1>
<p>{{ description }}</p>
</div>
<div class="confirmation-wrapper_links">
<a href="/cart">{{ 'Перейти к оформлению заказы'|t }}</a>
<a href="#">{{ 'Продолжить покупки'|t }}</a>
</div>
</div>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment