EmicoEcommerce / Magento2TweakwiseExport-archived

Magento 2 module for Tweakwise export
Other
6 stars 16 forks source link

Stock calculation method inconsistent #73

Closed edwinljacobs closed 4 years ago

edwinljacobs commented 5 years ago

Issue Brief

The stock decorator implements a method which should calculate stock quantity for a given composite exportEntity how much stock there is. This is the method:

/**
     * @param ExportEntity $entity
     * @param int $storeId
     * @return float
     */
    private function getCombinedStock(ExportEntity $entity, int $storeId): float
    {
        $stockQuantities = $this->getStockQuantities($entity);
        if (empty($stockQuantities)) {
            return 0;
        }
        switch ($this->config->getStockCalculation($storeId)) {
            case StockCalculation::OPTION_MAX:
                return max($stockQuantities);
            case StockCalculation::OPTION_MIN:
                return min($stockQuantities);
            case StockCalculation::OPTION_SUM:
            default:
                return array_sum($stockQuantities);
        }
    }

This method asks from config how this should be calculated, however this should depend on product type and not on config. The reason is that if config is set to OPTION_MAX then this works fine for a configurable but this does not work at all for a set or bundle, in this case a minimum of all child stock quantities would be better. We propose that each type should have its own class which implements the logic for that entity type.

For reference the value that is calculated ends up in the the feed as {{qty}}.

edwinljacobs commented 4 years ago

Has been fixed in https://github.com/EmicoEcommerce/Magento2TweakwiseExport/releases/tag/v1.6.0