Skip to main content
deleted 1 character in body
Source Link
Brad Bell
  • 67.6k
  • 6
  • 75
  • 145

iI am struggelingstruggling with closure and saving a variable.

In my class somePlugin i do have a public var $customerId , which should be updated after i execute my setUser() function. To do so i have a setter and getter function. In my init() function i do want to use the new var on a later EVENT_BEFORE_COMPLETE_ORDER event. However the variable $customerId does get reset to the default value after page reload.

How would i avoid that?

I tried using session but it seems like the session has been overwritten on reload as well

sender; $customerId = $this->getCustomerId(); // on every page reload it does get reset to the default var, what is not wanted $order->customerId = $customerId; } ); } public function setUser( $userId ) { self::$plugin = $this; // get userModel by userId $userModel = Craft::$app->users->getUserById( $userId ); // check if commerce record for craft user exists if ( ! $this->customers->getCustomerByUserId( $userId ) ) { // create and save new customer $newCustomer = new Customer(); $newCustomer->user = $userModel; $this->customers->saveCustomer( $newCustomer, false ); } // store customerId $customerId = $this->customers->getCustomerByUserId( $userId )->id; // sets the new and wanted it wich gets overwritten by page reload $this->setCustomerId( $customerId ); } public function setCustomerId( $customerId ) { $this->customerId = $customerId; } public function getCustomerId() { return $this->customerId; } }

i am struggeling with closure and saving a variable.

In my class somePlugin i do have a public var $customerId , which should be updated after i execute my setUser() function. To do so i have a setter and getter function. In my init() function i do want to use the new var on a later EVENT_BEFORE_COMPLETE_ORDER event. However the variable $customerId does get reset to the default value after page reload.

How would i avoid that?

I tried using session but it seems like the session has been overwritten on reload as well

sender; $customerId = $this->getCustomerId(); // on every page reload it does get reset to the default var, what is not wanted $order->customerId = $customerId; } ); } public function setUser( $userId ) { self::$plugin = $this; // get userModel by userId $userModel = Craft::$app->users->getUserById( $userId ); // check if commerce record for craft user exists if ( ! $this->customers->getCustomerByUserId( $userId ) ) { // create and save new customer $newCustomer = new Customer(); $newCustomer->user = $userModel; $this->customers->saveCustomer( $newCustomer, false ); } // store customerId $customerId = $this->customers->getCustomerByUserId( $userId )->id; // sets the new and wanted it wich gets overwritten by page reload $this->setCustomerId( $customerId ); } public function setCustomerId( $customerId ) { $this->customerId = $customerId; } public function getCustomerId() { return $this->customerId; } }

I am struggling with closure and saving a variable.

In my class somePlugin i do have a public var $customerId , which should be updated after i execute my setUser() function. To do so i have a setter and getter function. In my init() function i do want to use the new var on a later EVENT_BEFORE_COMPLETE_ORDER event. However the variable $customerId does get reset to the default value after page reload.

How would i avoid that?

I tried using session but it seems like the session has been overwritten on reload as well

sender; $customerId = $this->getCustomerId(); // on every page reload it does get reset to the default var, what is not wanted $order->customerId = $customerId; } ); } public function setUser( $userId ) { self::$plugin = $this; // get userModel by userId $userModel = Craft::$app->users->getUserById( $userId ); // check if commerce record for craft user exists if ( ! $this->customers->getCustomerByUserId( $userId ) ) { // create and save new customer $newCustomer = new Customer(); $newCustomer->user = $userModel; $this->customers->saveCustomer( $newCustomer, false ); } // store customerId $customerId = $this->customers->getCustomerByUserId( $userId )->id; // sets the new and wanted it wich gets overwritten by page reload $this->setCustomerId( $customerId ); } public function setCustomerId( $customerId ) { $this->customerId = $customerId; } public function getCustomerId() { return $this->customerId; } }
added 94 characters in body
Source Link
HendrikEng
  • 1.1k
  • 5
  • 18

i am struggeling with closure and saving a variable.

In my class somePlugin i do have a public var $customerId , which should be updated after i execute my setUser() function. To do so i have a setter and getter function. In my init() function i do want to use the new var on a later EVENT_BEFORE_COMPLETE_ORDER event. However the variable $customerId does get reset to the default value after page reload.

How would i avoid that?

I tried using session but it seems like the session has been overwritten on reload as well

sender; $customerId = $this->getCustomerId(); // on every page reload it does get reset to the default var, what is not wanted $order->customerId = $customerId; } ); } public function setUser( $userId ) { self::$plugin = $this; // get userModel by userId $userModel = Craft::$app->users->getUserById( $userId ); // check if commerce record for craft user exists if ( ! $this->customers->getCustomerByUserId( $userId ) ) { // create and save new customer $newCustomer = new Customer(); $newCustomer->user = $userModel; $this->customers->saveCustomer( $newCustomer, false ); } // store customerId $customerId = $this->customers->getCustomerByUserId( $userId )->id; // sets the new and wanted it wich gets overwritten by page reload $this->setCustomerId( $customerId ); } public function setCustomerId( $customerId ) { $this->customerId = $customerId; } public function getCustomerId() { return $this->customerId; } }

i am struggeling with closure and saving a variable.

In my class somePlugin i do have a public var $customerId , which should be updated after i execute my setUser() function. To do so i have a setter and getter function. In my init() function i do want to use the new var on a later EVENT_BEFORE_COMPLETE_ORDER event. However the variable $customerId does get reset to the default value after page reload.

How would i avoid that?

sender; $customerId = $this->getCustomerId(); // on every page reload it does get reset to the default var, what is not wanted $order->customerId = $customerId; } ); } public function setUser( $userId ) { self::$plugin = $this; // get userModel by userId $userModel = Craft::$app->users->getUserById( $userId ); // check if commerce record for craft user exists if ( ! $this->customers->getCustomerByUserId( $userId ) ) { // create and save new customer $newCustomer = new Customer(); $newCustomer->user = $userModel; $this->customers->saveCustomer( $newCustomer, false ); } // store customerId $customerId = $this->customers->getCustomerByUserId( $userId )->id; // sets the new and wanted it wich gets overwritten by page reload $this->setCustomerId( $customerId ); } public function setCustomerId( $customerId ) { $this->customerId = $customerId; } public function getCustomerId() { return $this->customerId; } }

i am struggeling with closure and saving a variable.

In my class somePlugin i do have a public var $customerId , which should be updated after i execute my setUser() function. To do so i have a setter and getter function. In my init() function i do want to use the new var on a later EVENT_BEFORE_COMPLETE_ORDER event. However the variable $customerId does get reset to the default value after page reload.

How would i avoid that?

I tried using session but it seems like the session has been overwritten on reload as well

sender; $customerId = $this->getCustomerId(); // on every page reload it does get reset to the default var, what is not wanted $order->customerId = $customerId; } ); } public function setUser( $userId ) { self::$plugin = $this; // get userModel by userId $userModel = Craft::$app->users->getUserById( $userId ); // check if commerce record for craft user exists if ( ! $this->customers->getCustomerByUserId( $userId ) ) { // create and save new customer $newCustomer = new Customer(); $newCustomer->user = $userModel; $this->customers->saveCustomer( $newCustomer, false ); } // store customerId $customerId = $this->customers->getCustomerByUserId( $userId )->id; // sets the new and wanted it wich gets overwritten by page reload $this->setCustomerId( $customerId ); } public function setCustomerId( $customerId ) { $this->customerId = $customerId; } public function getCustomerId() { return $this->customerId; } }
Source Link
HendrikEng
  • 1.1k
  • 5
  • 18

Closure in plugin class/ saving and passing a public property

i am struggeling with closure and saving a variable.

In my class somePlugin i do have a public var $customerId , which should be updated after i execute my setUser() function. To do so i have a setter and getter function. In my init() function i do want to use the new var on a later EVENT_BEFORE_COMPLETE_ORDER event. However the variable $customerId does get reset to the default value after page reload.

How would i avoid that?

sender; $customerId = $this->getCustomerId(); // on every page reload it does get reset to the default var, what is not wanted $order->customerId = $customerId; } ); } public function setUser( $userId ) { self::$plugin = $this; // get userModel by userId $userModel = Craft::$app->users->getUserById( $userId ); // check if commerce record for craft user exists if ( ! $this->customers->getCustomerByUserId( $userId ) ) { // create and save new customer $newCustomer = new Customer(); $newCustomer->user = $userModel; $this->customers->saveCustomer( $newCustomer, false ); } // store customerId $customerId = $this->customers->getCustomerByUserId( $userId )->id; // sets the new and wanted it wich gets overwritten by page reload $this->setCustomerId( $customerId ); } public function setCustomerId( $customerId ) { $this->customerId = $customerId; } public function getCustomerId() { return $this->customerId; } }