diff --git a/doc/3. Customization/Filters.md b/doc/3. Customization/Filters.md index 8ca2c12..caee29c 100644 --- a/doc/3. Customization/Filters.md +++ b/doc/3. Customization/Filters.md @@ -59,3 +59,5 @@ There are list of available filters: * *RetailcrmFilterSaveCorporateCustomerAddress* - built corporate customer address object, which will be saved to CMS * *RetailcrmFilterJobManagerIntervals* - array with jobs as keys and intervals as values +* *RetailcrmFilterWeight* - array with weight units in ICML +* *RetailcrmFilterMiddlewares* - array with middlewares, which running before and after request diff --git a/retailcrm/lib/RetailcrmCatalog.php b/retailcrm/lib/RetailcrmCatalog.php index 2c8a956..b9b1914 100644 --- a/retailcrm/lib/RetailcrmCatalog.php +++ b/retailcrm/lib/RetailcrmCatalog.php @@ -191,10 +191,7 @@ class RetailcrmCatalog $article = null; } - $weight = round($product['weight'], 2); - if (0.0 === $weight) { - $weight = null; - } + $weight = $this->getWeightInKg($product['weight']); $width = round($product['width'], 3); $height = round($product['height'], 3); @@ -366,10 +363,8 @@ class RetailcrmCatalog return $pictures; } - private static function getProductsCount( - $id_lang, - Context $context = null - ) { + private static function getProductsCount($id_lang, Context $context = null) + { if (!$context) { $context = Context::getContext(); } @@ -450,4 +445,71 @@ class RetailcrmCatalog return $parentId; } + + private function getWeightInKg($weight) + { + if (0 == $weight) { + return null; + } + + $mg = 1 / 1000 / 1000; + $g = 1 / 1000; + $ton = 1 * 1000; + $oz = 1 / 35.3; + $pd = 1 * 2.2; + $st = 1 * 6.35; + + $weightUnits = [ + 'mg' => $mg, + 'мг' => $mg, + 'miligramo' => $mg, + 'миллиграмм' => $mg, + 'milligram' => $mg, + + 'g' => $g, + 'gram' => $g, + 'grammo' => $g, + 'г' => $g, + 'гр' => $g, + 'грамм' => $g, + + 'kg' => 1, + 'kilogram' => 1, + 'kilogramme' => 1, + 'kilo' => 1, + 'kilogramo' => 1, + + 'ton' => $ton, + 'т' => $ton, + 'тонна' => $ton, + 'tonelada' => $ton, + 'toneladas' => $ton, + + 'oz' => $oz, + 'унция' => $oz, + 'ounce' => $oz, + 'onza' => $oz, + + 'pd' => $pd, + 'фунт' => $pd, + 'pound' => $pd, + 'lb' => $pd, + 'libra' => $pd, + 'paladio' => $pd, + + 'st' => $st, + 'стоун' => $st, + 'stone' => $st, + ]; + + $weightUnits = RetailcrmTools::filter('RetailcrmFilterWeight', $weightUnits); + + $weightUnit = Configuration::get('PS_WEIGHT_UNIT'); + + if (isset($weightUnits[$weightUnit])) { + return $weight * $weightUnits[$weightUnit]; + } + + return $weight; + } } diff --git a/retailcrm/lib/RetailcrmIcml.php b/retailcrm/lib/RetailcrmIcml.php index b5ff660..79761ce 100644 --- a/retailcrm/lib/RetailcrmIcml.php +++ b/retailcrm/lib/RetailcrmIcml.php @@ -62,12 +62,12 @@ class RetailcrmIcml 'productActivity', 'dimensions', 'vatRate', + 'weight', ]; $this->params = [ 'article' => 'Артикул', 'color' => 'Цвет', - 'weight' => 'Вес', 'tax' => 'Наценка', ]; }