Put variable from phtml to an observerHow to Set, Retrieve and Unset Session Variables in Magento 2?Collection in Event Observer: Using parentId from simple product to remove configurable productCategory Product List : add a custom view mode via observerMagento: Adding block from observer programmaticallyI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Set custom price of product when adding to cart code not workingPrice not getting updated for second product…Magento 2 Sending emails triggered by observerMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Enterprise edition, get all custom attributes of product in the observerSomething went wrong while saving the category in Magento 2.1.9
Can I grease a crank spindle/bracket without disassembling the crank set?
Dynamic SOQL query relationship with field visibility for Users
What happened to Captain America in Endgame?
I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?
Is the claim "Employers won't employ people with no 'social media presence'" realistic?
Why did some of my point & shoot film photos come back with one third light white or orange?
Multiple options vs single option UI
Don’t seats that recline flat defeat the purpose of having seatbelts?
Can we say “you can pay when the order gets ready”?
Who was the lone kid in the line of people at the lake at the end of Avengers: Endgame?
Overlay of two functions leaves gaps
What does the integral of a function times a function of a random variable represent, conceptually?
How did Captain America manage to do this?
Two field separators (colon and space) in awk
How to have a sharp product image?
How would 10 generations of living underground change the human body?
Betweenness centrality formula
Are there physical dangers to preparing a prepared piano?
What is the smallest unit of eos?
Pulling the rope with one hand is as heavy as with two hands?
How can I print the prosodic symbols in LaTeX?
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
How can I practically buy stocks?
Alignment of various blocks in tikz
Put variable from phtml to an observer
How to Set, Retrieve and Unset Session Variables in Magento 2?Collection in Event Observer: Using parentId from simple product to remove configurable productCategory Product List : add a custom view mode via observerMagento: Adding block from observer programmaticallyI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Set custom price of product when adding to cart code not workingPrice not getting updated for second product…Magento 2 Sending emails triggered by observerMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Enterprise edition, get all custom attributes of product in the observerSomething went wrong while saving the category in Magento 2.1.9
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to send a variable from a phtml to an observer through an event observer. Is that possible?
Note: variables are defined by a script in the phtml.
Edit:
The name of event is "checkout_cart_product_add_after".
In the script I have some like this:
function cambio_telas(event)
telaactual = event.data.tela;
And I want to send the var "telaactual" to the observer:
public function execute(MagentoFrameworkEventObserver $observer)
$item = $observer->getEvent()->getData('quote_item');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$additionalOptions = array(
array(
'label' => 'Tela',
'value' => 'tela02'
)
In short, I need to apply the variable "currentdata" to value in "$ aditionalOptions"
magento-2.1 event-observer
add a comment |
I'm trying to send a variable from a phtml to an observer through an event observer. Is that possible?
Note: variables are defined by a script in the phtml.
Edit:
The name of event is "checkout_cart_product_add_after".
In the script I have some like this:
function cambio_telas(event)
telaactual = event.data.tela;
And I want to send the var "telaactual" to the observer:
public function execute(MagentoFrameworkEventObserver $observer)
$item = $observer->getEvent()->getData('quote_item');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$additionalOptions = array(
array(
'label' => 'Tela',
'value' => 'tela02'
)
In short, I need to apply the variable "currentdata" to value in "$ aditionalOptions"
magento-2.1 event-observer
Please add some more information like which event, variable. Also addscriptto get clear idea.
– Abhishek Panchal
Aug 25 '17 at 21:21
thx for you recomendation.
– Andrés Felipe López
Aug 25 '17 at 21:39
add a comment |
I'm trying to send a variable from a phtml to an observer through an event observer. Is that possible?
Note: variables are defined by a script in the phtml.
Edit:
The name of event is "checkout_cart_product_add_after".
In the script I have some like this:
function cambio_telas(event)
telaactual = event.data.tela;
And I want to send the var "telaactual" to the observer:
public function execute(MagentoFrameworkEventObserver $observer)
$item = $observer->getEvent()->getData('quote_item');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$additionalOptions = array(
array(
'label' => 'Tela',
'value' => 'tela02'
)
In short, I need to apply the variable "currentdata" to value in "$ aditionalOptions"
magento-2.1 event-observer
I'm trying to send a variable from a phtml to an observer through an event observer. Is that possible?
Note: variables are defined by a script in the phtml.
Edit:
The name of event is "checkout_cart_product_add_after".
In the script I have some like this:
function cambio_telas(event)
telaactual = event.data.tela;
And I want to send the var "telaactual" to the observer:
public function execute(MagentoFrameworkEventObserver $observer)
$item = $observer->getEvent()->getData('quote_item');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$additionalOptions = array(
array(
'label' => 'Tela',
'value' => 'tela02'
)
In short, I need to apply the variable "currentdata" to value in "$ aditionalOptions"
magento-2.1 event-observer
magento-2.1 event-observer
edited Apr 23 at 13:51
Arshad Hussain
4591929
4591929
asked Aug 25 '17 at 21:13
Andrés Felipe LópezAndrés Felipe López
14
14
Please add some more information like which event, variable. Also addscriptto get clear idea.
– Abhishek Panchal
Aug 25 '17 at 21:21
thx for you recomendation.
– Andrés Felipe López
Aug 25 '17 at 21:39
add a comment |
Please add some more information like which event, variable. Also addscriptto get clear idea.
– Abhishek Panchal
Aug 25 '17 at 21:21
thx for you recomendation.
– Andrés Felipe López
Aug 25 '17 at 21:39
Please add some more information like which event, variable. Also add
script to get clear idea.– Abhishek Panchal
Aug 25 '17 at 21:21
Please add some more information like which event, variable. Also add
script to get clear idea.– Abhishek Panchal
Aug 25 '17 at 21:21
thx for you recomendation.
– Andrés Felipe López
Aug 25 '17 at 21:39
thx for you recomendation.
– Andrés Felipe López
Aug 25 '17 at 21:39
add a comment |
1 Answer
1
active
oldest
votes
You can use getData() and setData()
in phtml :
$myVal = 'hello';
Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1
in Observer :
Mage::getSingleton('core/session')->getData('value1'); //you get the saved value in value1
Mage::getSingleton('core/session')->unsetData('value1'); // you empty the value1 value from session for the next use.
Edit:
Sorry, I didn't see that you want the Magento 2, there was no tag, however I'm not Magento 2, but you can follow this tuto:
https://magento.stackexchange.com/a/94267/48355
Hi this works for magento 2.1??? .. i need some configuration?? when i use Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1 the page crash.
– Andrés Felipe López
Aug 27 '17 at 19:15
Please, look my update
– PЯINCƏ
Aug 27 '17 at 19:39
:) nice, now i have defined ´function getCheckoutSession()´ in my block, but ´$this->getCheckoutSession()->getMyValue();´ no work in observer... I think I missed something but I do not know.
– Andrés Felipe López
Aug 27 '17 at 20:21
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f190655%2fput-variable-from-phtml-to-an-observer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use getData() and setData()
in phtml :
$myVal = 'hello';
Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1
in Observer :
Mage::getSingleton('core/session')->getData('value1'); //you get the saved value in value1
Mage::getSingleton('core/session')->unsetData('value1'); // you empty the value1 value from session for the next use.
Edit:
Sorry, I didn't see that you want the Magento 2, there was no tag, however I'm not Magento 2, but you can follow this tuto:
https://magento.stackexchange.com/a/94267/48355
Hi this works for magento 2.1??? .. i need some configuration?? when i use Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1 the page crash.
– Andrés Felipe López
Aug 27 '17 at 19:15
Please, look my update
– PЯINCƏ
Aug 27 '17 at 19:39
:) nice, now i have defined ´function getCheckoutSession()´ in my block, but ´$this->getCheckoutSession()->getMyValue();´ no work in observer... I think I missed something but I do not know.
– Andrés Felipe López
Aug 27 '17 at 20:21
add a comment |
You can use getData() and setData()
in phtml :
$myVal = 'hello';
Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1
in Observer :
Mage::getSingleton('core/session')->getData('value1'); //you get the saved value in value1
Mage::getSingleton('core/session')->unsetData('value1'); // you empty the value1 value from session for the next use.
Edit:
Sorry, I didn't see that you want the Magento 2, there was no tag, however I'm not Magento 2, but you can follow this tuto:
https://magento.stackexchange.com/a/94267/48355
Hi this works for magento 2.1??? .. i need some configuration?? when i use Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1 the page crash.
– Andrés Felipe López
Aug 27 '17 at 19:15
Please, look my update
– PЯINCƏ
Aug 27 '17 at 19:39
:) nice, now i have defined ´function getCheckoutSession()´ in my block, but ´$this->getCheckoutSession()->getMyValue();´ no work in observer... I think I missed something but I do not know.
– Andrés Felipe López
Aug 27 '17 at 20:21
add a comment |
You can use getData() and setData()
in phtml :
$myVal = 'hello';
Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1
in Observer :
Mage::getSingleton('core/session')->getData('value1'); //you get the saved value in value1
Mage::getSingleton('core/session')->unsetData('value1'); // you empty the value1 value from session for the next use.
Edit:
Sorry, I didn't see that you want the Magento 2, there was no tag, however I'm not Magento 2, but you can follow this tuto:
https://magento.stackexchange.com/a/94267/48355
You can use getData() and setData()
in phtml :
$myVal = 'hello';
Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1
in Observer :
Mage::getSingleton('core/session')->getData('value1'); //you get the saved value in value1
Mage::getSingleton('core/session')->unsetData('value1'); // you empty the value1 value from session for the next use.
Edit:
Sorry, I didn't see that you want the Magento 2, there was no tag, however I'm not Magento 2, but you can follow this tuto:
https://magento.stackexchange.com/a/94267/48355
edited Aug 27 '17 at 19:39
answered Aug 25 '17 at 23:55
PЯINCƏPЯINCƏ
8,47431147
8,47431147
Hi this works for magento 2.1??? .. i need some configuration?? when i use Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1 the page crash.
– Andrés Felipe López
Aug 27 '17 at 19:15
Please, look my update
– PЯINCƏ
Aug 27 '17 at 19:39
:) nice, now i have defined ´function getCheckoutSession()´ in my block, but ´$this->getCheckoutSession()->getMyValue();´ no work in observer... I think I missed something but I do not know.
– Andrés Felipe López
Aug 27 '17 at 20:21
add a comment |
Hi this works for magento 2.1??? .. i need some configuration?? when i use Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1 the page crash.
– Andrés Felipe López
Aug 27 '17 at 19:15
Please, look my update
– PЯINCƏ
Aug 27 '17 at 19:39
:) nice, now i have defined ´function getCheckoutSession()´ in my block, but ´$this->getCheckoutSession()->getMyValue();´ no work in observer... I think I missed something but I do not know.
– Andrés Felipe López
Aug 27 '17 at 20:21
Hi this works for magento 2.1??? .. i need some configuration?? when i use Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1 the page crash.
– Andrés Felipe López
Aug 27 '17 at 19:15
Hi this works for magento 2.1??? .. i need some configuration?? when i use Mage::getSingleton('core/session')->setData('value1', $myVal); //save data in value1 the page crash.
– Andrés Felipe López
Aug 27 '17 at 19:15
Please, look my update
– PЯINCƏ
Aug 27 '17 at 19:39
Please, look my update
– PЯINCƏ
Aug 27 '17 at 19:39
:) nice, now i have defined ´function getCheckoutSession()´ in my block, but ´$this->getCheckoutSession()->getMyValue();´ no work in observer... I think I missed something but I do not know.
– Andrés Felipe López
Aug 27 '17 at 20:21
:) nice, now i have defined ´function getCheckoutSession()´ in my block, but ´$this->getCheckoutSession()->getMyValue();´ no work in observer... I think I missed something but I do not know.
– Andrés Felipe López
Aug 27 '17 at 20:21
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f190655%2fput-variable-from-phtml-to-an-observer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Please add some more information like which event, variable. Also add
scriptto get clear idea.– Abhishek Panchal
Aug 25 '17 at 21:21
thx for you recomendation.
– Andrés Felipe López
Aug 25 '17 at 21:39