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;








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"










share|improve this question
























  • 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

















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"










share|improve this question
























  • 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













0












0








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"










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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

















  • 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
















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










1 Answer
1






active

oldest

votes


















0














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






share|improve this answer

























  • 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











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%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









0














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






share|improve this answer

























  • 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















0














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






share|improve this answer

























  • 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













0












0








0







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






share|improve this answer















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







share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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

















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%2f190655%2fput-variable-from-phtml-to-an-observer%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

Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림