seikan / cart Goto Github PK
View Code? Open in Web Editor NEWA simple PHP shopping cart class to use in ecommerce web applications.
License: MIT License
A simple PHP shopping cart class to use in ecommerce web applications.
License: MIT License
I am trying to use this class to implement into my shopping cart and according to the examples i am creating entries in my cart and i am trying to use a non-numeric value as 'id' and then later call it in my cart
$cart->add('hash123',1, [
'image' =>'some-jpg-123.jpg'
]);
// later
foreach(c::get('cart')->getItems() as $items):
foreach($items as $cart):
<a href="/thumbs/<?php echo byHash($cart['id']) ?>/<?php echo $cart['attributes']['image'] ?>">....</a>
endforeach;
endforeach;
when outputting the raw data, it doesn't have any sort of "id" index... output is for example:
Array
(
[1lgw886] => Array
(
[0] => Array
(
[quantity] => 1
[hash] => 8fdd062086410a3f8cc5552c3c4f9363
[attributes] => Array
(
[image] => studio-black-2017-18-41-00.jpg
)
)
)
)
Hello,
i have try to add update of product not quantity but attribute
I use Ajax
$poscart->update(5, 2, [ 'price' => 8.00,'name'=>'New name']);
but not work ... where I make error ?
hey any chance you can provide me an example of this working through using a database for the data?
Hey, the array is faulty. i cant see the ID
I'm finding your cart very interesting, i wondered why the product are inside a double array?
I'm curious to kown the reason. Thank You Very Much!
Array
(
[1] => Array
(
[0] => Array
(
[id] => 1
[quantity] => 1
[hash] => 82aa6954b3eecf592b1e8fb86063fd80
[attributes] => Array
(
[price] => 349
[color] => Silver
)
)
)
[2] => Array
(
[0] => Array
(
[id] => 2
[quantity] => 1
[hash] => a4da6514bfe02e8b9ad747387005561a
[attributes] => Array
(
[price] => 449
[color] => Silver
[size] => Small
)
)
)
)
Hi what happen if I add two products with the color red, and other with white color both dame id but then I want to change one to a blue color how that work with this class?
Hi using your example, I have found that an item sometimes 1 item does not get removed. tried to add 3 items of the same id with different colors, and removing although get this error:
However sometimes there is no error and just doesnt allow me to delete the rest of the items. See if you're able to reproduce this error, by just adding different colors of the same product. then deleting one by one, you'll see that for some reason one of them wont delete
Only small remark ///
This is not working - itemMaxQuantity' => 99, // 0 = Unlimited
When set to 0 - it is really zero.
First of all, thanks for the class, it works great. However, I found a small bug while using product variants. If you add two or more variants of the same product to the cart, and removes the one with index 0, the indexing goes bad. This is because, the array doesn't get re-indexed after item removal, and each cart operation starts at index 0. I found that re-indexing the variant arrays after the removal of a variant fixes this.
public function remove($id, $attributes = []){
...
unset($this->items[$id][$index]);
$this->items[$id] = array_values($this->items[$id]);
...
}
Hi, I have a button for update but how can I update all items not just one?
// Update item
if (isset($_POST['update'])) {
$cart->update($_POST['id'], $_POST['qty'], [
'price' => $_POST['price'],
'color' => (isset($_POST['color'])) ? $_POST['color'] : '',
'size' => (isset($_POST['size'])) ? $_POST['size'] : '',
]);
}
In the example, the price is the same even if the color of the same product differs.
But how can I implement it if I want to set a price by color?
I don't think the update cart function is working. I tried on the example.php file you provided. it doesn't really work
I have a project that this could be amazing with but was wondering how we would implement the following:
Ultimately we would also like to set limits based on supplier or category (whichever is easier)
Whichever way is easier to implement..
Any assistance would be great :) thank you in advance.
I'd love to see this cart solution twice in use: One for a classic cart. And another "cart" as a favorite list to tag products that you want to buy later or products you want to compare.
Hello,
i cant update the quantity of my cart.
here is my code:
`
if($_GET['do'] == "change")
{
$quantity = $_POST['quantity'];
$id = $_GET['id'];
$cart->update($id, $quantity);
header('location: cart.php');
exit;
}
`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.