RatMD / oc-mall-plugin

E-Commerce solution for October CMS
https://offline-gmbh.github.io/oc-mall-plugin
MIT License
0 stars 0 forks source link

Price and Tax handling / Extend CartProduct / Better totals strategy #12

Open SamBrishes opened 7 months ago

SamBrishes commented 7 months ago

The totals / price values which are added using the CartItemPriceAccessors trait are not "jsonable" at the moment, which becomes problematic when used via Rest-API / headless env.

A hotfix I I'm using is the extension of the CartProduct model using a dynamic method

CartProduct::extend(function (CartProduct $model) {
    $model->append('totals');
    $model->addDynamicMethod('getTotalsAttribute', function () use ($model) {
        return [
            'pre_taxes'             => $model->getTotalPreTaxesAttribute(),
            'taxes'                 => $model->getTotalTaxesAttribute(),
            'post_taxes'            => $model->getTotalPostTaxesAttribute(),
            'weight'                => $model->getTotalWeightAttribute(),
            'product_pre_taxes'     => $model->getProductPreTaxesAttribute(),
            'product_taxes'         => $model->getProductTaxesAttribute(),
            'product_post_taxes'    => $model->getProductPostTaxesAttribute(),
        ];
    });
});

The price handling with / without taxes may should be rethinked in general. The designations are confusing and could lead to incorrect expenditure.

Related issues

SamBrishes commented 7 months ago

Related issue

https://github.com/OFFLINE-GmbH/oc-mall-plugin/issues/12