1 2 3 4 5 6 7 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Newsletter\Controller\Subscriber\NewAction"> <plugin name="Newsletter_Subscriber_NewAction" type="Magemonkeys\AjaxNewsletter\Controller\Plugin\Subscriber\NewAction" sortOrder="10" disabled="false" /> </type> </config> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
<?php /** * */ namespace Magemonkeys\AjaxNewsletter\Controller\Plugin\Subscriber; use Magento\Customer\Api\AccountManagementInterface as CustomerAccountManagement; use Magento\Customer\Model\Session; use Magento\Customer\Model\Url as CustomerUrl; use Magento\Framework\App\Action\Context; use Magento\Store\Model\StoreManagerInterface; use Magento\Newsletter\Model\SubscriberFactory; /** * Class NewAction */ class NewAction extends \Magento\Newsletter\Controller\Subscriber\NewAction { /** * @var CustomerAccountManagement */ protected $customerAccountManagement; protected $resultJsonFactory; /** * Initialize dependencies. * * @param Context $context * @param SubscriberFactory $subscriberFactory * @param Session $customerSession * @param StoreManagerInterface $storeManager * @param CustomerUrl $customerUrl * @param CustomerAccountManagement $customerAccountManagement */ public function __construct( Context $context, SubscriberFactory $subscriberFactory, Session $customerSession, StoreManagerInterface $storeManager, CustomerUrl $customerUrl, CustomerAccountManagement $customerAccountManagement, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory ) { $this->customerAccountManagement = $customerAccountManagement; $this->resultJsonFactory = $resultJsonFactory; parent::__construct( $context, $subscriberFactory, $customerSession, $storeManager, $customerUrl, $customerAccountManagement ); } /** * Retrieve available Order fields list * * @return array */ public function aroundExecute($subject, $procede) { $response = []; if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email')) { $email = (string)$this->getRequest()->getPost('email'); try { $this->validateEmailFormat($email); $this->validateGuestSubscription(); $this->validateEmailAvailable($email); $status = $this->_subscriberFactory->create()->subscribe($email); if ($status == \Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE) { $response = [ 'status' => 'OK', 'msg' => 'The confirmation request has been sent.', ]; } else { $response = [ 'status' => 'OK', 'msg' => 'Thank you for your subscription.', ]; } } catch (\Magento\Framework\Exception\LocalizedException $e) { $response = [ 'status' => 'ERROR', 'msg' => __('There was a problem with the subscription: %1', $e->getMessage()), ]; } catch (\Exception $e) { $response = [ 'status' => 'ERROR', 'msg' => __('Something went wrong with the subscription.'), ]; } } return $this->resultJsonFactory->create()->setData($response); } } |
1 2 3 4 5 |
{ "*": { "js/newsletter_subscriber_ajax": { } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
require.config({ deps: [ 'jquery' ], callback: function ($) { var form = $('form.subscribe'); form.submit(function(e) { if(form.validation('isValid')){ var email = $("#newsletter").val(); var url = form.attr('action'); var loadingMessage = $('#loading-message'); if(loadingMessage.length == 0) { form.find('.control').append('<div id="loading-message" style="display:none;padding-top:10px;"> </div>'); var loadingMessage = $('#loading-message'); } e.preventDefault(); try{ loadingMessage.html('Submitting...').show(); $.ajax({ url: url, dataType: 'json', type: 'POST', data: {email: email}, success: function (data){ if(data.status != "ERROR"){ $('#newsletter').val(''); } loadingMessage.html(data.msg); }, complete: function(){ setTimeout(function(){ loadingMessage.hide(); },5000); } }); } catch (e){ loadingMessage.html(e.message); } } return false; }); } }) |
[crayon-63e0a3545e1d9930148355/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.