Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Fixe cart php notice when cart is not initialized with weight/length options
givanzc392a824f72b
diff --git a/app/component/cart.php b/app/component/cart.phpindex 42e6d5b..c157580 100755--- a/app/component/cart.php+++ b/app/component/cart.php@@ -22,6 +22,7 @@namespace Vvveb\Component;+use function Vvveb\siteSettings;use Vvveb\System\Cart\Cart as ShoppingCart;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;@@ -42,6 +43,10 @@ class Cart extends ComponentBase {protected $options = [];function results() {+ $site = siteSettings($this->options['site_id'], $this->options['language_id']);+ $this->options += array_intersect_key($site,+ array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id']));+$cart = ShoppingCart::getInstance($this->options);$results['products'] = $cart->getAll();$results['coupons'] = $cart->getCoupons();diff --git a/app/component/site.php b/app/component/site.phpindex c56fedb..df61046 100755--- a/app/component/site.php+++ b/app/component/site.php@@ -29,7 +29,8 @@ use Vvveb\System\Event;class Site extends ComponentBase {public static $defaultOptions = [- 'site_id' => null,+ 'site_id' => null,+ 'language_id' => null,];protected $options = [];diff --git a/app/controller/cart/cart.php b/app/controller/cart/cart.phpindex ffc66d7..bfc68f8 100755--- a/app/controller/cart/cart.php+++ b/app/controller/cart/cart.php@@ -31,41 +31,46 @@ use Vvveb\System\Shipping;class Cart extends Base {use CouponTrait;- function index() {+ private $cart;++ function init() {+ parent::init();+$options = array_intersect_key($this->global['site'],array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id']));- $cart = ShoppingCart::getInstance($options);- $payment = Payment::getInstance();- $shipping = Shipping::getInstance();+ $this->cart = ShoppingCart::getInstance($this->global + $options);+ }++ function index() {+ $payment = Payment::getInstance();+ $shipping = Shipping::getInstance();$this->view->payment = $payment->getMethods([]);$this->view->shipping = $shipping->getMethods([]);if (isset($this->request->post['product_id']) &&(isset($this->request->get['route']) && $this->request->get['route'] == 'cart/cart/add')) {- $cart->add($this->request->post['product_id']);+ $this->cart->add($this->request->post['product_id']);}$cart = [- 'products' => $cart->getAll(),- 'totals' => $cart->getTotals(),- 'total_items' => $cart->getNoProducts(),- 'total_weight' => $cart->getWeight(),- 'total_price' => $cart->getNoProducts(),- 'total' => $cart->getGrandTotal(),- 'coupons' => $cart->getCoupons(),- 'total_formatted' => $cart->getGrandTotalFormatted(),- 'weight_unit' => $this->global['site']['weight_type'],- 'length_unit' => $this->global['site']['length_type']+ 'products' => $this->cart->getAll(),+ 'totals' => $this->cart->getTotals(),+ 'total_items' => $this->cart->getNoProducts(),+ 'total_weight' => $this->cart->getWeight(),+ 'total_price' => $this->cart->getNoProducts(),+ 'total' => $this->cart->getGrandTotal(),+ 'coupons' => $this->cart->getCoupons(),+ 'total_formatted' => $this->cart->getGrandTotalFormatted(),+ 'weight_unit' => $this->global['site']['weight_type'],+ 'length_unit' => $this->global['site']['length_type'],];$this->view->cart = $cart;}private function action($action, $productId = null, $quantity = 1) {- $cart = ShoppingCart::getInstance($this->global);-$productId = $this->request->request['product_id'] ?? false;$key = $this->request->request['key'] ?? false;$quantity = $this->request->request['quantity'] ?? $quantity;@@ -76,21 +81,21 @@ class Cart extends Base {//$this->view->success = false;switch ($action) {case 'add':- $cart->add($productId, $quantity, $option, $subscriptionPlanId);+ $this->cart->add($productId, $quantity, $option, $subscriptionPlanId);break;case 'update':- $cart->update($key, $quantity);+ $this->cart->update($key, $quantity);break;case 'remove':- $cart->remove($key);+ $this->cart->remove($key);break;}- //$this->view->success = $cart->$action($productId, $quantity);+ //$this->view->success = $this->cart->$action($productId, $quantity);}$this->view->noJson = true;diff --git a/app/controller/cart/coupon-trait.php b/app/controller/cart/coupon-trait.phpindex d9d4520..57e8209 100644--- a/app/controller/cart/coupon-trait.php+++ b/app/controller/cart/coupon-trait.php@@ -23,16 +23,13 @@namespace Vvveb\Controller\Cart;use function Vvveb\__;-use Vvveb\System\Cart\Cart as ShoppingCart;trait CouponTrait {function coupon() {$coupon = $this->request->request['coupon'] ?? '';if ($coupon) {- $cart = ShoppingCart::getInstance($this->global);-- if ($cart->addCoupon($coupon)) {+ if ($this->cart->addCoupon($coupon)) {$this->view->success['coupon'] = __('Coupon successfully applied!');} else {$this->view->errors['coupon'] = __('Invalid or expired coupon!');@@ -46,9 +43,7 @@ trait CouponTrait {$coupon = $this->request->request['coupon'] ?? '';if ($coupon) {- $cart = ShoppingCart::getInstance($this->global);-- if ($cart->removeCoupon($coupon)) {+ if ($this->cart->removeCoupon($coupon)) {$this->view->success['coupon'] = __('Coupon removed!');} else {$this->view->errors['coupon'] = __('Could not remove coupon!');