1. Go to this page and download the library: Download azmolla/laravelcart library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
Cart::update($rowId, 2); // Will update the quantity
Cart::update($rowId, ['name' => 'Product 1']); // Will update the name
Cart::update($rowId, $product); // Will update the id, name and price
public function updateOption(string $optionKey, mixed $optionValue);
use Azmolla\Shoppingcart\Facades\Cart;
$rowId = 'some-unique-row-id';
$cartItem = Cart::get($rowId);
if ($cartItem) {
// Update the 'make_free' option to true for this cart item
$cartItem->updateOption('is_free', true);
// Optionally, you can check the updated options
$updatedOptions = $cartItem->options->all();
print_r($updatedOptions); // This will show the updated options
}
Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99);
// Get the content of the 'shopping' cart
Cart::content();
Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, ['size' => 'medium']);
// Get the content of the 'wishlist' cart
Cart::content();
// If you want to get the content of the 'shopping' cart again
Cart::instance('shopping')->content();
// And the count of the 'wishlist' cart again
Cart::instance('wishlist')->count();
// First we'll add the item to the cart.
$cartItem = Cart::add('293ad', 'Product 1', 1, 9.99, ['size' => 'large']);
// Next we associate a model with the item.
Cart::associate($cartItem->rowId, Product::class);
// Or even easier, call the associate method on the CartItem!
$cartItem->associate(Product::class);
// You can even make it a one-liner
Cart::add('293ad', 'Product 1', 1, 9.99, ['size' => 'large'])->associate(Product::class);
// Now, when iterating over the content of the cart, you can access the model.
foreach(Cart::content() as $row) {
echo 'You have ' . $row->qty . ' items of ' . $row->model->name . ' with description: "' . $row->model->description . '" in your cart.';
}
$cartItem = Cart::add('201b84a2-e345-4b6f-934e-dc4d85567a21', 'Product 1', 1, 9.99, ['model_field' => 'uuid'])->associate(Product::class);
foreach(Cart::content() as $row) {
echo 'You have ' . $row->qty . ' items of ' . $row->model->name . ' with uuid: "' . $row->model->uuid . '" in your cart.';
}
// Add some items in your Controller.
Cart::add('192ao12', 'Product 1', 1, 9.99);
Cart::add('1239ad0', 'Product 2', 2, 5.95, ['size' => 'large']);
// Set an additional cost (on the same page where you display your cart content)
Cart::addCost(Cart::COST_TRANSACTION, 0.10);
Cart::addCost(Cart::COST_SHIPPING, 5.00);
Cart::addCost('somethingelse', 1.11);
// Display the content in a View.
<table>
<thead>
<tr>
<th>Product</th>
<th>Qty</th>
<th>Price</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
foreach(Cart::content() as $row) :
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.