I am a backend developer. Currently, I work mainly on open source.
- I am a developer of the Yii Framework.
- I am a founder of the HTTP Software.
- I have a tiny blog in Russian.
- You can reach me via email.
Shopping cart for Yii2
License: BSD 3-Clause "New" or "Revised" License
I am a backend developer. Currently, I work mainly on open source.
Hi guys, this is the FloatCalculator
class. Create a directory in app
folder, e.g. in my case is utils
, create the file FloatCalculator.php
and paste it:
<?php
namespace app\utils;
use devanych\cart\calculators\CalculatorInterface;
class FloatCalculator implements CalculatorInterface
{
/**
* @param \devanych\cart\CartItem[] $items
* @return integer
*/
public function getCost(array $items)
{
$cost = 0;
foreach ($items as $item) {
$cost += ( $item->getQuantity() * $item->getProduct()->price );
}
return $cost;
}
/**
* @param \devanych\cart\CartItem[] $items
* @return integer
*/
public function getCount(array $items)
{
$count = 0;
foreach ($items as $item) {
$count += $item->getQuantity();
}
return $count;
}
}
Remember to change the line 'calculatorClass' => 'devanych\cart\calculators\SimpleCalculator'
in 'calculatorClass' => 'app\utils\FloatCalculator'
in web.php
.
Byeeeeeeee
When the CartItem
calculates the total cost of the item, it applies a ceil()
call. I don't think this is necessary, in fact this can cause issues, because the getPrice()
and getCost()
might return different values. This is a screenshot demonstrating this from our webshop:
Do you think that removing the ceil()
call is a viable solution for this issue?
Здравствуйте Есть две сущность offer и product В корзину добавляю offer. Есть необходимость получить сущность product по связи описанной в модели offer Как это сделать у каждого item когда я получаю список в корзине cart->getItems() и прохожусь по массиву?
If you use DbSessionStorage, you must be configured such.
'cartDb' => [ 'class' => 'common\components\Cart', 'storageClass' => 'common\storage\DbSessionStorage', 'calculatorClass' => 'common\components\Calculator', 'params' => [ 'key' => 'cart', 'expire' => 604800, 'productClass' => 'common\models\Product', 'productFieldId' => 'id' ], ],
The CartItem class accepts price as float, but when retrieving the total cost, the SimpleCalculator cast them as integer
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.