/**
     * Get the mapping data: referrer
     *
     * @return array
     */
    public function getReferrer()
    {
        // s_core_tax
        $rows = Shopware()->Db()->query('
					SELECT
							C.id, C.company name,
							IFNULL(PMC.plentyID, 0) plentyID
						FROM s_emarketing_partner C
						LEFT JOIN plenty_mapping_referrer PMC
							ON PMC.shopwareID = C.id
						WHERE active = 1
						ORDER BY C.company
			')->fetchAll();
        $referrer = PlentymarketsImportController::getOrderReferrerList();
        foreach ($rows as &$row) {
            if ($row['plentyID']) {
                $row['plentyName'] = $referrer[$row['plentyID']]['name'];
            } else {
                if ($this->auto) {
                    foreach ($referrer as $plentyData) {
                        $distance = levenshtein($row['name'], $plentyData['name']);
                        if ($distance <= 2 || strstr($plentyData['name'], $row['name'])) {
                            $row['plentyName'] = $plentyData['name'];
                            $row['plentyID'] = $plentyData['id'];
                            PlentymarketsMappingController::addReferrer($row['id'], $plentyData['id']);
                            if ($distance == 0) {
                                break;
                            }
                        }
                    }
                } else {
                    $row['plentyName'] = '';
                }
            }
        }
        return $rows;
    }
 /**
  * Loads the referrer list data
  */
 public function getReferrerListAction()
 {
     $this->View()->assign(array('success' => true, 'data' => array_values(PlentymarketsImportController::getOrderReferrerList())));
 }
 /**
  * Runs the mapping cleanup cronjob.
  *
  * @param Shopware_Components_Cron_CronJob $Job
  */
 public function runMappingCleanup(Shopware_Components_Cron_CronJob $Job)
 {
     // Check the connection
     if (!$this->Status->mayImport()) {
         return;
     }
     PlentymarketsLogger::getInstance()->message('Cleanup:Mapping', 'Starting');
     // Reset the timestamps
     PlentymarketsConfig::getInstance()->setMiscCustomerClassLastImport(0);
     PlentymarketsConfig::getInstance()->setMiscMethodsOfPaymentLastImport(0);
     PlentymarketsConfig::getInstance()->setMiscSalesOrderReferrerLastImport(0);
     PlentymarketsConfig::getInstance()->setMiscShippingProfilesLastImport(0);
     PlentymarketsConfig::getInstance()->setMiscMultishopsLastImport(0);
     PlentymarketsConfig::getInstance()->setMiscVatLastImport(0);
     // Get fresh data
     PlentymarketsImportController::getCustomerClassList();
     PlentymarketsImportController::getMethodOfPaymentList();
     PlentymarketsImportController::getOrderReferrerList();
     PlentymarketsImportController::getShippingProfileList();
     PlentymarketsImportController::getStoreList();
     PlentymarketsImportController::getVatList();
     PlentymarketsLogger::getInstance()->message('Cleanup:Mapping', 'Finished');
 }