/**
     * Get the mapping data: methods of payment
     *
     * @return array
     */
    public function getMethodOfPayment()
    {
        // s_core_tax
        $rows = Shopware()->Db()->query('
					SELECT
							C.id, C.description name,
							IFNULL(PMC.plentyID, -1) plentyID
						FROM s_core_paymentmeans C
						LEFT JOIN plenty_mapping_method_of_payment PMC
							ON PMC.shopwareID = C.id
						WHERE active = 1
						ORDER BY C.name
				')->fetchAll();
        $plentyShipping = PlentymarketsImportController::getMethodOfPaymentList();
        foreach ($rows as &$row) {
            if ($row['plentyID'] >= 0) {
                $row['plentyName'] = $plentyShipping[$row['plentyID']]['name'];
            } else {
                if ($this->auto) {
                    foreach ($plentyShipping 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::addMethodOfPayment($row['id'], $plentyData['id']);
                            if ($distance == 0) {
                                break;
                            }
                        }
                    }
                } else {
                    $row['plentyName'] = '';
                }
            }
        }
        return $rows;
    }
 /**
  * Loads the plenty mapping data
  */
 public function getPlentyMappingDataAction()
 {
     $forceReload = $this->Request()->get('force', false);
     switch ($this->Request()->map) {
         case 'Country':
             $data = PlentymarketsConfig::getInstance()->getMiscCountriesSorted();
             break;
         case 'Currency':
             $data = PlentymarketsConfig::getInstance()->getMiscCurrenciesSorted();
             break;
         case 'MeasureUnit':
             $data = PlentymarketsConfig::getInstance()->getItemMeasureUnits();
             break;
         case 'Vat':
             if ($forceReload) {
                 PlentymarketsConfig::getInstance()->setMiscVatLastImport(0);
             }
             $data = PlentymarketsImportController::getVatList();
             break;
         case 'Referrer':
             if ($forceReload) {
                 PlentymarketsConfig::getInstance()->setMiscSalesOrderReferrerLastImport(0);
             }
             $data = PlentymarketsImportController::getOrderReferrerList();
             break;
         case 'ShippingProfile':
             if ($forceReload) {
                 PlentymarketsConfig::getInstance()->setMiscShippingProfilesLastImport(0);
             }
             $data = PlentymarketsImportController::getShippingProfileList();
             break;
         case 'MethodOfPayment':
             if ($forceReload) {
                 PlentymarketsConfig::getInstance()->setMiscMethodsOfPaymentLastImport(0);
             }
             $data = PlentymarketsImportController::getMethodOfPaymentList();
             break;
         case 'CustomerClass':
             if ($forceReload) {
                 PlentymarketsConfig::getInstance()->setMiscCustomerClassLastImport(0);
             }
             $data = PlentymarketsImportController::getCustomerClassList();
             break;
         case 'Shop':
             if ($forceReload) {
                 PlentymarketsConfig::getInstance()->setMiscMultishopsLastImport(0);
             }
             $data = PlentymarketsImportController::getStoreList();
             break;
         case 'OrderStatus':
         case 'PaymentStatus':
             if ($forceReload) {
                 PlentymarketsConfig::getInstance()->setMiscOrderStatusLastImport(0);
             }
             $data = PlentymarketsImportController::getOrderStatusList();
             foreach ($data as &$d) {
                 $d['id'] = $d['status'];
             }
             break;
     }
     $this->View()->assign(array('success' => true, 'data' => array_values($data)));
 }
 /**
  * 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');
 }