Skip to content

Instantly share code, notes, and snippets.

@PetraMotz
Last active August 4, 2021 11:13
Show Gist options
  • Save PetraMotz/a12b5778038fb354c85b164f57b15466 to your computer and use it in GitHub Desktop.
Save PetraMotz/a12b5778038fb354c85b164f57b15466 to your computer and use it in GitHub Desktop.
PHP #shoppingcart #warenkorb #php
Beispiel deFlorian
create, edit, update, IMMER NON CACHABLE!!!!!
Im Extension builider unter Switchable Actions
Warenkorb
Product->shoppingCart;
hinzufügen. speichern, DB aktualisieren, Cache flushen;
im ext/Configuration/ ExtensionBuilder/settings.yaml auch Merge /Kepp Einstellungen achten!!
overwriteSettings:
Classes:
Controller: keep
Domain:
Model: merge
Repository: keep
Configuration:
#TCA merge not possible - use overrides directory
TCA: overrides directory
TypoScript: keep
FlexForms: merge
Resources:
Private:
Language: merge
Templates: keep
user_extension.svg: keep
Im ProductsController eine neue Action hinzufügen
/**
* action shoppingCart
*
* @return void
*/
public function shoppingCartAction() {
$items = json_decode($_COOKIE['shoppingCart'], true); -> shoppingCart ist in diesem Fall der Name des cookies da vorher im main.js gepeichert wurde
$.cookie("shoppingCart", JSON.stringify(cart), {path: '/'}); -> cart ist das Array in das die Werte gepusht wurden
cart.push( {'uid': uid, 'amount': amount});
if (is_array($items)) {
foreach ($items as &$item) {
$item['product'] = $this->productRepository->findByUid($item['uid']);
}
}
$this->view->assign('items', $items);
}
Unter ext/Templates/ Product neue View hinzufügen (ShoppingCart.html)
von dort aus kann dann über {items} auf die gespeicherten Items und über {item.product.title} auf die Product Properties zugegriffen werden
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment