/** * Get the mapping data: measure units * * @return array */ public function getMeasureUnit() { $rows = Shopware()->Db()->query(' SELECT C.id, CONCAT(C.description, " (", C.unit, ")") name, C.description, C.unit, IFNULL(PMC.plentyID, 0) plentyID FROM s_core_units C LEFT JOIN plenty_mapping_measure_unit PMC ON PMC.shopwareID = C.id ORDER BY C.description ')->fetchAll(); $plentyMU = PlentymarketsConfig::getInstance()->getItemMeasureUnits(); foreach ($rows as &$row) { if ($row['plentyID']) { $row['plentyName'] = $plentyMU[$row['plentyID']]['name']; } else { if ($this->auto) { $plentyUnits = PlentymarketsConfig::getInstance()->getItemMeasureUnits(); foreach ($plentyUnits as $plentyData) { preg_match('/(.*?) \\((.*?)\\)/', $plentyData['name'], $matches); if (!is_array($matches)) { $name = $plentyData['name']; $unit = ''; } else { list($match, $name, $unit) = $matches; } $distance = levenshtein($row['description'], $name); if ($row['unit'] == $unit || $distance <= 2) { $row['plentyName'] = $plentyData['name']; $row['plentyID'] = $plentyData['id']; PlentymarketsMappingController::addMeasureUnit($row['id'], $plentyData['id']); break; } } } else { $row['plentyName'] = ''; } } } return $rows; }