Comments (7)
Hello @ll-r-magner
The $temp = new Cart();
should throw an error. It is not an issue. PHP 8.0 has more strict rules and class constructor expecting 1 argument provided.
In order to achieve what you want use next code
use BigCommerce\Cart\Cart;
use BigCommerce\Container\Api;
$container = bigcommerce()->container();
$cart_api = $container[ Api::FACTORY ]->cart();
$cart = new Cart( $cart_api );
$cart->get_cart_id()
First you get a global container. Than you get cart api entity and only after that you will be able to use Cart
class.
$cart = bigcommerce()->cart;
won't work for you because it provides cart container and not a card itself.
Please let me know if this helps or you have additional question
from bigcommerce-for-wordpress.
Fatal error: Uncaught ArgumentCountError: Too few arguments to function BigCommerce\Cart\Cart::__construct(), 0 passed in /www/ledgeclone121222_223/public/wp-content/themes/ll-ecommerce/page-templates/ll-umbrellas-pdp.php on line 317 and exactly 1 expected in /www/ledgeclone121222_223/public/wp-content/plugins/bigcommerce/src/BigCommerce/Cart/Cart.php:34 Stack trace: #0 /www/ledgeclone121222_223/public/wp-content/themes/ll-ecommerce/page-templates/ll-umbrellas-pdp.php(317): BigCommerce\Cart\Cart->__construct() #1 /www/ledgeclone121222_223/public/wp-includes/template.php(783): require_once('/www/ledgeclone...') #2 /www/ledgeclone121222_223/public/wp-content/themes/ll-ecommerce/bigcommerce/single-bigcommerce_product.php(48): load_template('/www/ledgeclone...') #3 /www/ledgeclone121222_223/public/wp-includes/template-loader.php(106): include('/www/ledgeclone...') #4 /www/ledgeclone121222_223/public/wp-blog-header.php(19): require_once('/www/ledgeclone...') #5 /www/ledgeclone121222_223/public/index.php(17): require('/www/ledgeclone...') #6 {main} thrown in /www/ledgeclone121222_223/public/wp-content/plugins/bigcommerce/src/BigCommerce/Cart/Cart.php on line 34
There has been a critical error on this website.
from bigcommerce-for-wordpress.
Also have tried syntax $cart = bigcommerce()->cart;
then calling it via $bc_cart_id = $cart->get_cart_id();
from bigcommerce-for-wordpress.
@MlKilderkin sorry im late to this been super busy. So that code works to create a new cart correct? What if a cart already exists and im just trying to add a new item to cart?
from bigcommerce-for-wordpress.
Hello @ll-r-magner no problem. Code above creates an object that allows to retrieve card id stored in cookies.
from bigcommerce-for-wordpress.
@MlKilderkin Ok, while I was waiting for a reply just now I think I was able to get it. If you dont mind checking out what im doing here. The "add_to_cart" function was created by another dev which I can share if need be. Our products are a little over engineered so some extra logic is required. As far as dealing with the Cart() object does this look right?
UPDATE: Well adding this product to cart didnt throw a PHP error so thats progress. I am getting a 400 response when adding to cart though.
UPDATE V2: So, because the add_to_cart function relies on redirecting to the cart page it does work as intended however, we use the BC4WP setting AJAX Add to Cart which doesn't redirect. Is there a way to make certain template files redirect while allowing the majority to use the global setting? @MlKilderkin
if (!empty($_POST)) {
// cart id from bigcommerce cookie
$container = bigcommerce()->container();
$cart_api = $container[ Api::FACTORY ]->cart();
$cart = new Cart( $cart_api );
$bc_cart_id = $cart->get_cart_id();
// $cart->get_cart_id()
// $cart = bigcommerce()->cart;
// $bc_cart_id = $cart->get_cart_id();
$post_product = \BigCommerce\Post_Types\Product\Product::by_product_id( $_POST['product'] );
if (isset($bc_cart_id) && $bc_cart_id !== '') {
// cart has been created already
add_to_cart($post_product, $_POST, $bc_cart_id);
header('Location: /cart');
} else {
// cart has not been created
$container = bigcommerce()->container();
$cart_api = $container[ Api::FACTORY ]->cart();
$cart = new Cart( $cart_api );
// $cart->get_cart_id();
$new_cart = add_to_cart($post_product, $_POST, null);
$cart->set_cart_id($new_cart['data']['id']);
header('Location: /cart');
}
}
from bigcommerce-for-wordpress.
@MlKilderkin Is there a way to set a single page to redirect to /cart on add to cart and have the rest of the pages do the AJAX add to cart function (not redirecting to cart)?
from bigcommerce-for-wordpress.
Related Issues (20)
- Product sync stuck at 'requesting store information' HOT 7
- Support for Elementor Pro single post templates on product pages HOT 1
- 5.0 breaks website HOT 12
- Sync still broken in 5.0.1 HOT 2
- Embedded Checkout Error HOT 3
- Add exclusive offers field to BC4WP registration form
- CDN image size in category pages
- Product sync stalls at step 6 - Updating brands HOT 2
- New Products get synced into "Draft" HOT 2
- Products Shortcode does not allow displaying a single result in the grid template
- WordPress plugin does not successfully import some categories HOT 1
- Unable to sync products between Bigcommerce and WordPress. Get Description
- Suppliesplus.wpengine.com - Unable to sync products to WP. Possible Brands import issue.
- Moving closer to WPCS
- Checkout Broken Within Multi Channel Store
- Variation image in Cart fetching from local WP instead of BC CDN
- Product variation with multiple options cannot be aded to cart HOT 1
- Unable to sync products between BigCommerce and Dreamhost WordPress HOT 7
- BigCommerce <= 5.0.7 - Unauthenticated Sensitive Information Exposure
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bigcommerce-for-wordpress.