Answer the question
In order to leave comments, you need to log in
How to render a fragment?
In general, the essence is as follows, there is a basket, there is a button to add to basket. On the button weighs data-request = "onAddToCart"
Below is onAddToCart itself
public function onAddToCart(){
$product = \vladimir\catalog\Models\Product::find( Input::get('id') );
if (Input::get('qty') !== null){
$qty = Input::get('qty');
}
$item = new \stdClass();
$item->id = $product->id;
$item->name = $product->name;
$item->price = $product->price;
$item->img = $product->images[0]->path;
$item->qty = count($this->getItems());
Session::push('cart', $item);
return [
'@.cart-items' => $this->renderPartial('@cart-item.htm', ['item' => $item]),
'.total-price' => $this->renderPartial('@cart-price.htm', ['item' => $this->Total()]),
'.qty-cart' => $this->renderPartial('@qty-cart.htm', ['qty' => count($this->getItems())])
];
}
public function onClearOneItemCart(){
foreach ($this->getItems() as $key => $value) {
if($value->id == Input::get('id')){
Session::pull('cart.'.$key);
}
}
return [
'@.cart-items' => $this->renderPartial('@cart-item.htm')
];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question