yii2mod / yii2-cart Goto Github PK
View Code? Open in Web Editor NEWYii2 shopping cart
License: MIT License
Yii2 shopping cart
License: MIT License
There is a small bug in your design. You assume that the VAT is static on a product. However it is not. It depends on the location of the customer.
When I add a product, and then I supply my customer data the VAT could change based on the customers country
How ,i can send parameter qty , price and packaging.
And Price is depends by packaging
Example.
$id = $model->id
$product = MBarang::findOne($id);
$price = $model->price
$packaging = $model->packaging
$qty = $model->qty
I see I could specify itemType to get the total, but how do I set the itemtype ?
Please explain that this is a Unique Id for the cartitem. not the product itself.
So if I have 1 product, 4 times added, there should be 4 different unique ID's
I am trying to help out, not to critisize your work.... hope you appreciate it
Hello. i have installed extension and also migration as well but widget shows empty data id , label and price. how to add product to cart? also in migration there is no any product table added to database.
Hi,
Is there a method make me add the quantity to the cart and count the total by the quantity?
Thanks
'components' => [
'cart' => [
'class' => 'yii2mod\cart\Cart',
'storageClass' => 'yii2mod\cart\storage\DatabaseStorage'
],
]
How can I save the cart in this code?
/** @var $cart \yii2mod\cart\Cart */
$cart = app()->cart;
foreach ($products as $product) {
$cart->add($product, false);
}
Solution:
public function save()
{
$this->storage->save($this);
}
public function clear($save = true)
{
$this->items = [];
$save && $this->save();
return $this;
}
public function add(CartItemInterface $element, $save = true)
{
$this->addItem($element);
$save && $this->save();
return $this;
}
public function remove($uniqueId, $save = true)
{
if (!isset($this->items[$uniqueId])) {
throw new InvalidParamException('Item not found');
}
unset($this->items[$uniqueId]);
$save && $this->save();
return $this;
}
It seems that you forgot to specify that getVat needs to be implemented in your docs
ase table or view not found: 1146 Table 'mxcom0_dev.cart' doesn't exist
The SQL being executed was: SELECT cartData
FROM cart
WHERE sessionId
=1
Error Info: Array
It looks for a table named 'cart' however the migration creates the correct 'prefix_cart'
So I guess there is a missing prefix in the code somewhere
Mac-mini-Dev:*** dev$ php yii migrate/redo 3
Yii Migration Tool (based on Yii v2.0.15.1)
Total 3 migrations to be redone:
m161119_153348_alter_cart_data
m161109_124936_rename_cart_table
m160516_095943_init
Redo the above migrations? (yes|no) [no]:yes
*** reverting m161119_153348_alter_cart_data
Exception 'ReflectionException' with message 'Class m161119_153348_alter_cart_data does not exist'
system: windows 10 16299.64
database: PostgreSql9.1
in path\vendor\yiisoft\yii2\db\Schema.php:636
Error Info:
Array
(
[0] => 42601
[1] => 7
[2] => ERROR: syntax error at or near "" LINE 4: PRIMARY KEY (
sessionId`)
^
)
I tried to modify this file after the success
$this->createTable('{{%Cart}}', [
'sessionId' => $this->string(),
'cartData' => $this->text(),
], $tableOptions);
$this->addPrimaryKey('cart_primary_key', '{{%Cart}}', 'sessionId');
The CartItemInterface.php
uses int data type for price value:
public function getPrice(): int;
I believe that more correct would be to have this value float/double to support decimal values in prices. In version <1.4 it was originally untyped function, so it was no problem.
I propose changing the signature to float.
Is there a possiblity to add a product and order it 6 times ? I seem to be able to only add 1 product at a time, and that multiple qty show on different lines
First I want to mention that I'm on PHP 7.2.13, now the problem:
SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: '77g9t9t5u5qdvrogoi4j0muiam'
The SQL being executed was: DELETE FROM cart
WHERE sessionId
=1
I resolve this by chaning this: (DatabaseStorage.php Line:132)
$command->delete($this->table, [$this->idField => $identifier]);
to this:
$command->delete($this->table, [$this->idField => (string)$identifier]);
Hello,
I have this error:
Argument 1 passed to yii2mod\cart\Cart::add() must be an instance of yii2mod\cart\models\CartItemInterface
is in this method:
public function add(CartItemInterface $element, $save = true): self
I follow the doc and configured the extension in correct way:
'cart' => [
'class' => 'yii2mod\cart\Cart',
// you can change default storage class as following:
'storageClass' => [
'class' => 'yii2mod\cart\storage\DatabaseStorage',
// you can also override some properties
'deleteIfEmpty' => true
]
],
Then in my controller, just this simple code:
public function actionCart()
{
$cart = \Yii::$app->cart;
$cart->add(2);
}
I tried to:
Where I am wrong?
Thank you
Hi,
Your extension looks a good alternative for my project but I cant understand the difference between a Product and an Item in the interface that are supposed to be implemented in my models.
I really look forward to test the conversion to order :)
Thanks
At file DatabaseStorage.php, if not active session, maybe can't use Yii::$app->session->getId()
but you can active session at init(), just like:
Yii::$app->session->open();
Good luck!
When I use this command, I got error:
$cart->add($item);
The problem is from DatabaseStorage::save() in this line
REPLACE {{{$this->table}}}
SET
{{{$this->dataField}}} = :val,
{{{$this->idField}}} = :id
The property $table you declare above is already in correct syntax ({{%cart}}), no need to add more double-curly braces
I already have this error:
Declaration of backend\models\Product::getPrice() must be compatible with yii2mod\cart\models\CartItemInterface::getPrice(): int
I already implement the CartInterface and functions and got this error
Hello,
I'm trying to add a product to the cart using the $cart->add(Product::findOne($id)
method, but it throws the following exception:
Error Info: Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{{
cart}} SET
cartData = 'a:1:{i:1;O:18:\' at line 1 )
It seems to me that the "" character is not allowed in MySQL database.
I have the following setup, and your latest composer version of the cart (yii2mod/yii2-cart v1.4):
Is there anything that needs to be changed?
The problem that my model have an annonymouce functions.
and there is no possibility to avoid this use case...
When you save to the table you use the user_id , but when you get back the products from the cart table you use the sessionId .
Please take a look on the below code i think is fixed now :
Where I can find CartProductInterface?
Returns a string containing a byte-stream representation of value that can be stored anywhere.
Note that this is a binary string which may include null bytes, and needs to be stored and handled as such. For example, serialize() output should generally be stored in a BLOB field in a database, rather than a CHAR or TEXT field.
reference php.net
The cartData column may change the type to blob or be processed to base64_encode/base64_decode before serialize/unserialize
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.