Giter Club home page Giter Club logo

yii2-cart's Introduction

Hi, I am Evgeniy 👋

I am a backend developer. Currently, I work mainly on open source.

yii2-cart's People

Contributors

devanych avatar shahjadin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

yii2-cart's Issues

FloatCalculator useful to get a TotalCost in float

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

Ceil on total cost calculation

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:

Screenshot_1

Do you think that removing the ceil() call is a viable solution for this issue?

Доступ к по Reference

Здравствуйте Есть две сущность offer и product В корзину добавляю offer. Есть необходимость получить сущность product по связи описанной в модели offer Как это сделать у каждого item когда я получаю список в корзине cart->getItems() и прохожусь по массиву?

If you use DbSessionStorage, you must be configured such.

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' ],          ],

getTotalCost as float

The CartItem class accepts price as float, but when retrieving the total cost, the SimpleCalculator cast them as integer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.