Jump to content

Session Cart Events


Blesta Addons

Recommended Posts

i have my own order_type , i want to make some extra validation when a cart is updated .

 

in my order_type_xxxx.php i have the update item  callabeck , but is not triggers when i update or edit the cart item . and to make sur is working , i have made a simple function , when a product is updated/edited the updateItem callback should normally empty the cart , but is not working !!!

public function updateItem(EventObject $event) {
 $this->cart->emptyCart(); 
}

is something i need to do or any error in my part ?

 

 

ADDED :

 

the same for remove item event  , no result

public function removeItem(EventObject $event) {
  // $params = $event->getParams();
  $this->cart->emptyCart();
}
Link to comment
Share on other sites

i'm talking about the  order_types . if you look to order_type_domain.php you will find a events like

public function prequeueItem(EventObject $event) {}

and

public function addItem(EventObject $event) {}

and they are working and i'm using them . but the updateItem() and removeItem() event not working .

 

from session cart componenets

/**
  * Adds an item to the cart
  *
  * @param mixed $item The item to add to the cart
  * @return int The index the item was added to
  */
public function addItem($item) {
  $cart = $this->get();
  $i = count($cart['items']);
 
  $cart['items'][$i] = $item;
  $this->setData("items", $cart['items']);
 
  $event = new EventObject("SessionCart." . $this->cart_name . ".addItem", array('item' => $item, 'index' => $i));
  $this->Events->trigger($event);
 
  return $i;
}

/**
  * Update an item in the cart
  *
  * @param int $index The index to update
  * @param mixed $item The item to update at the given index
  */
public function updateItem($index, $item) {
  $cart = $this->get();
  $cart['items'][$index] = $item;
  $this->setData("items", $cart['items']);
 
  $event = new EventObject("SessionCart." . $this->cart_name . ".updateItem", array('item' => $item, 'index' => $index));
  $this->Events->trigger($event);
}
Link to comment
Share on other sites

Hello Tyson , i found it , i should add the callback first in the order_type

public function setCart(SessionCart $cart) {
  parent::setCart($cart);
  $this->cart->setCallback("prequeueItem", array($this, "prequeueItem"));
  $this->cart->setCallback("addItem", array($this, "addItem"));
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...