How to display a popup on the product page at the touch of a button, add to the basket? Magento 2





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















There is an event that checks if the goods in the basket when we go to the product page. If there is an attribute in the goods that allows to deliver the goods on the day of the order, if this attribute is included in the product, then it returns "1" if it is disabled, then there is nothing.
Now how to show the popup when you click on "add to cart" on the product page if there is already a product in the basket with the possibility of delivery today, and the second product that we want to add does not have this possibility.
And on the pop-up there should be two buttons, "Continue" or "Cancel". If the user clicks "Continue" then we add the item to the basket, and if the user clicks "Cancel", then we close the popup and there is nothing to add to the basket.




Observer->DayDelivery.php




namespace RonisSameDayDeliveryObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoCatalogModelResourceModelProductCollectionFactory;

class DayDelivery implements ObserverInterface
{
protected $resultPageFactory;

/**
* @var MagentoCheckoutModelCart
*/
protected $_cart;
protected $_productCollectionFactory;
protected $_resultJsonFactory;

/**
* [__construct description]
* @param MagentoFrameworkAppActionContext $context [description]
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory [description]
* @param MagentoCheckoutModelCart $cart [description]
*/
public function __construct(
MagentoFrameworkControllerResultJsonFactory $resultJsonFactory,
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoCheckoutModelCart $cart,
CollectionFactory $productCollectionFactory
)
{
$this->resultPageFactory = $resultPageFactory;
$this->_cart = $cart;
$this->_resultJsonFactory = $resultJsonFactory;
$this->_productCollectionFactory = $productCollectionFactory;
}

public function execute(MagentoFrameworkEventObserver $observer)
{
$writer = new ZendLogWriterStream(BP . '/var/log/samDayDelivery.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

$cartProductIds = $this->_cart->getQuoteProductIds();
$productCollection = $this->_productCollectionFactory->create();
if (!$cartProductIds) {
return false;
} else {
$productCollection->addFieldToFilter('entity_id', ['in' => [$cartProductIds]]);
$productCollection->addAttributeToSelect('allow_same_day_delivery');
foreach ($productCollection as $item) {
$id = $item->getId();
$check = $item->getData('allow_same_day_delivery');
$logger->info('Delivery sam day id: ' . $id . ' status ' . $check);
}
// $result = $this->_resultJsonFactory->create()->setData(['Shipment check' => $check]);
// return $result;
}
}
}









share|improve this question





























    0















    There is an event that checks if the goods in the basket when we go to the product page. If there is an attribute in the goods that allows to deliver the goods on the day of the order, if this attribute is included in the product, then it returns "1" if it is disabled, then there is nothing.
    Now how to show the popup when you click on "add to cart" on the product page if there is already a product in the basket with the possibility of delivery today, and the second product that we want to add does not have this possibility.
    And on the pop-up there should be two buttons, "Continue" or "Cancel". If the user clicks "Continue" then we add the item to the basket, and if the user clicks "Cancel", then we close the popup and there is nothing to add to the basket.




    Observer->DayDelivery.php




    namespace RonisSameDayDeliveryObserver;

    use MagentoFrameworkEventObserverInterface;
    use MagentoCatalogModelResourceModelProductCollectionFactory;

    class DayDelivery implements ObserverInterface
    {
    protected $resultPageFactory;

    /**
    * @var MagentoCheckoutModelCart
    */
    protected $_cart;
    protected $_productCollectionFactory;
    protected $_resultJsonFactory;

    /**
    * [__construct description]
    * @param MagentoFrameworkAppActionContext $context [description]
    * @param MagentoFrameworkViewResultPageFactory $resultPageFactory [description]
    * @param MagentoCheckoutModelCart $cart [description]
    */
    public function __construct(
    MagentoFrameworkControllerResultJsonFactory $resultJsonFactory,
    MagentoFrameworkAppActionContext $context,
    MagentoFrameworkViewResultPageFactory $resultPageFactory,
    MagentoCheckoutModelCart $cart,
    CollectionFactory $productCollectionFactory
    )
    {
    $this->resultPageFactory = $resultPageFactory;
    $this->_cart = $cart;
    $this->_resultJsonFactory = $resultJsonFactory;
    $this->_productCollectionFactory = $productCollectionFactory;
    }

    public function execute(MagentoFrameworkEventObserver $observer)
    {
    $writer = new ZendLogWriterStream(BP . '/var/log/samDayDelivery.log');
    $logger = new ZendLogLogger();
    $logger->addWriter($writer);

    $cartProductIds = $this->_cart->getQuoteProductIds();
    $productCollection = $this->_productCollectionFactory->create();
    if (!$cartProductIds) {
    return false;
    } else {
    $productCollection->addFieldToFilter('entity_id', ['in' => [$cartProductIds]]);
    $productCollection->addAttributeToSelect('allow_same_day_delivery');
    foreach ($productCollection as $item) {
    $id = $item->getId();
    $check = $item->getData('allow_same_day_delivery');
    $logger->info('Delivery sam day id: ' . $id . ' status ' . $check);
    }
    // $result = $this->_resultJsonFactory->create()->setData(['Shipment check' => $check]);
    // return $result;
    }
    }
    }









    share|improve this question

























      0












      0








      0








      There is an event that checks if the goods in the basket when we go to the product page. If there is an attribute in the goods that allows to deliver the goods on the day of the order, if this attribute is included in the product, then it returns "1" if it is disabled, then there is nothing.
      Now how to show the popup when you click on "add to cart" on the product page if there is already a product in the basket with the possibility of delivery today, and the second product that we want to add does not have this possibility.
      And on the pop-up there should be two buttons, "Continue" or "Cancel". If the user clicks "Continue" then we add the item to the basket, and if the user clicks "Cancel", then we close the popup and there is nothing to add to the basket.




      Observer->DayDelivery.php




      namespace RonisSameDayDeliveryObserver;

      use MagentoFrameworkEventObserverInterface;
      use MagentoCatalogModelResourceModelProductCollectionFactory;

      class DayDelivery implements ObserverInterface
      {
      protected $resultPageFactory;

      /**
      * @var MagentoCheckoutModelCart
      */
      protected $_cart;
      protected $_productCollectionFactory;
      protected $_resultJsonFactory;

      /**
      * [__construct description]
      * @param MagentoFrameworkAppActionContext $context [description]
      * @param MagentoFrameworkViewResultPageFactory $resultPageFactory [description]
      * @param MagentoCheckoutModelCart $cart [description]
      */
      public function __construct(
      MagentoFrameworkControllerResultJsonFactory $resultJsonFactory,
      MagentoFrameworkAppActionContext $context,
      MagentoFrameworkViewResultPageFactory $resultPageFactory,
      MagentoCheckoutModelCart $cart,
      CollectionFactory $productCollectionFactory
      )
      {
      $this->resultPageFactory = $resultPageFactory;
      $this->_cart = $cart;
      $this->_resultJsonFactory = $resultJsonFactory;
      $this->_productCollectionFactory = $productCollectionFactory;
      }

      public function execute(MagentoFrameworkEventObserver $observer)
      {
      $writer = new ZendLogWriterStream(BP . '/var/log/samDayDelivery.log');
      $logger = new ZendLogLogger();
      $logger->addWriter($writer);

      $cartProductIds = $this->_cart->getQuoteProductIds();
      $productCollection = $this->_productCollectionFactory->create();
      if (!$cartProductIds) {
      return false;
      } else {
      $productCollection->addFieldToFilter('entity_id', ['in' => [$cartProductIds]]);
      $productCollection->addAttributeToSelect('allow_same_day_delivery');
      foreach ($productCollection as $item) {
      $id = $item->getId();
      $check = $item->getData('allow_same_day_delivery');
      $logger->info('Delivery sam day id: ' . $id . ' status ' . $check);
      }
      // $result = $this->_resultJsonFactory->create()->setData(['Shipment check' => $check]);
      // return $result;
      }
      }
      }









      share|improve this question














      There is an event that checks if the goods in the basket when we go to the product page. If there is an attribute in the goods that allows to deliver the goods on the day of the order, if this attribute is included in the product, then it returns "1" if it is disabled, then there is nothing.
      Now how to show the popup when you click on "add to cart" on the product page if there is already a product in the basket with the possibility of delivery today, and the second product that we want to add does not have this possibility.
      And on the pop-up there should be two buttons, "Continue" or "Cancel". If the user clicks "Continue" then we add the item to the basket, and if the user clicks "Cancel", then we close the popup and there is nothing to add to the basket.




      Observer->DayDelivery.php




      namespace RonisSameDayDeliveryObserver;

      use MagentoFrameworkEventObserverInterface;
      use MagentoCatalogModelResourceModelProductCollectionFactory;

      class DayDelivery implements ObserverInterface
      {
      protected $resultPageFactory;

      /**
      * @var MagentoCheckoutModelCart
      */
      protected $_cart;
      protected $_productCollectionFactory;
      protected $_resultJsonFactory;

      /**
      * [__construct description]
      * @param MagentoFrameworkAppActionContext $context [description]
      * @param MagentoFrameworkViewResultPageFactory $resultPageFactory [description]
      * @param MagentoCheckoutModelCart $cart [description]
      */
      public function __construct(
      MagentoFrameworkControllerResultJsonFactory $resultJsonFactory,
      MagentoFrameworkAppActionContext $context,
      MagentoFrameworkViewResultPageFactory $resultPageFactory,
      MagentoCheckoutModelCart $cart,
      CollectionFactory $productCollectionFactory
      )
      {
      $this->resultPageFactory = $resultPageFactory;
      $this->_cart = $cart;
      $this->_resultJsonFactory = $resultJsonFactory;
      $this->_productCollectionFactory = $productCollectionFactory;
      }

      public function execute(MagentoFrameworkEventObserver $observer)
      {
      $writer = new ZendLogWriterStream(BP . '/var/log/samDayDelivery.log');
      $logger = new ZendLogLogger();
      $logger->addWriter($writer);

      $cartProductIds = $this->_cart->getQuoteProductIds();
      $productCollection = $this->_productCollectionFactory->create();
      if (!$cartProductIds) {
      return false;
      } else {
      $productCollection->addFieldToFilter('entity_id', ['in' => [$cartProductIds]]);
      $productCollection->addAttributeToSelect('allow_same_day_delivery');
      foreach ($productCollection as $item) {
      $id = $item->getId();
      $check = $item->getData('allow_same_day_delivery');
      $logger->info('Delivery sam day id: ' . $id . ' status ' . $check);
      }
      // $result = $this->_resultJsonFactory->create()->setData(['Shipment check' => $check]);
      // return $result;
      }
      }
      }






      magento2 checkout json






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Рома ЛытарьРома Лытарь

      1789




      1789






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269315%2fhow-to-display-a-popup-on-the-product-page-at-the-touch-of-a-button-add-to-the%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269315%2fhow-to-display-a-popup-on-the-product-page-at-the-touch-of-a-button-add-to-the%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Alcázar de San Juan

          Griza ansero

          Heinkel He 51