/**
     * Saves the settings
     */
    public function saveSettingsAction()
    {
        $Config = PlentymarketsConfig::getInstance();
        // Previous Hash
        $apiUserHash = $Config->getApiUserHash('');
        // API
        // Sanitize the Wsdl
        $wsdlParts = parse_url($this->Request()->ApiWsdl);
        $wsdl = sprintf('%s://%s', $wsdlParts['scheme'], $wsdlParts['host']);
        $Config->setApiWsdl($wsdl);
        $Config->setApiUsername($this->Request()->ApiUsername);
        $Config->setApiPassword($this->Request()->ApiPassword);
        $Config->setApiIgnoreGetServerTime((int) $this->Request()->ApiIgnoreGetServerTime);
        $Config->setApiUseGzipCompression((int) $this->Request()->ApiUseGzipCompression);
        $Config->setApiLogHttpHeaders((int) $this->Request()->ApiLogHttpHeaders);
        $Config->setApiHideCallsInLog((int) $this->Request()->ApiHideCallsInLog);
        $hash = md5($wsdl . $this->Request()->ApiUsername . $this->Request()->ApiPassword);
        if ($apiUserHash != $hash) {
            $Config->setApiUserHash($hash);
            $Config->setApiUserID(-1);
            $Config->setApiLastAuthTimestamp('');
            $Config->setApiToken('');
            // Check the connection
            PlentymarketsStatus::getInstance()->isConnected();
        }
        // Item
        $Config->setItemWarehouseID($this->Request()->ItemWarehouseID);
        $Config->setItemConfiguratorSetType($this->Request()->ItemConfiguratorSetType);
        $Config->setItemCleanupActionID($this->Request()->ItemCleanupActionID);
        $Config->setItemCategoryRootID($this->Request()->ItemCategoryRootID);
        $Config->setItemImageSyncActionID($this->Request()->ItemImageSyncActionID == true ? IMPORT_ITEM_IMAGE_SYNC : IMPORT_ITEM_IMAGE_NO_SYNC);
        $Config->setItemImageAltAttributeID($this->Request()->ItemImageAltAttributeID);
        $Config->setItemCategorySyncActionID($this->Request()->ItemCategorySyncActionID == true ? IMPORT_ITEM_CATEGORY_SYNC : IMPORT_ITEM_CATEGORY_NO_SYNC);
        $Config->setItemNumberImportActionID($this->Request()->ItemNumberImportActionID == true ? IMPORT_ITEM_NUMBER : IMPORT_ITEM_NUMBER_NO);
        $Config->setItemNumberSourceKey($this->Request()->ItemNumberSourceKey);
        $Config->setItemVariationNumberSourceKey($this->Request()->ItemVariationNumberSourceKey);
        $Config->setItemBundleHeadActionID($this->Request()->ItemBundleHeadActionID == true ? IMPORT_ITEM_BUNDLE_HEAD : IMPORT_ITEM_BUNDLE_HEAD_NO);
        $Config->setItemShortDescriptionImportActionID($this->Request()->ItemShortDescriptionImportActionID == true ? IMPORT_ITEM_SHORTDESC : IMPORT_ITEM_SHORTDESC_NO);
        $Config->setItemLongDescriptionImportActionID($this->Request()->ItemLongDescriptionImportActionID == true ? IMPORT_ITEM_LONGDESC : IMPORT_ITEM_LONGDESC_NO);
        $Config->setItemKeywordsImportActionID($this->Request()->ItemKeywordsImportActionID == true ? IMPORT_ITEM_KEYWORDS : IMPORT_ITEM_KEYWORDS_NO);
        $Config->setItemNameImportActionID($this->Request()->ItemNameImportActionID);
        $Config->setItemPriceImportActionID($this->Request()->ItemPriceImportActionID);
        $Config->setItemFreetextsImportActionID($this->Request()->ItemFreetextsImportActionID == true ? IMPORT_ITEM_FREETEXTS : IMPORT_ITEM_FREETEXTS_NO);
        $Config->setItemAssociateImportActionID($this->Request()->ItemAssociateImportActionID == PlentymarketsImportItemAssociateController::ACTION_DETACHED ? PlentymarketsImportItemAssociateController::ACTION_DETACHED : PlentymarketsImportItemAssociateController::ACTION_CHAINED);
        $Config->setDefaultCustomerGroupKey($this->Request()->DefaultCustomerGroupKey);
        $Config->setItemWarehousePercentage($this->Request()->ItemWarehousePercentage);
        $Config->setItemProducerID($this->Request()->ItemProducerID);
        $Config->setOrderMarking1($this->Request()->OrderMarking1);
        $Config->setOrderAdditionalCouponIdentifiers($this->Request()->OrderAdditionalCouponIdentifiers);
        $Config->setOrderReferrerID($this->Request()->OrderReferrerID);
        $Config->setOrderPaidStatusID(implode('|', $this->Request()->OrderPaidStatusID));
        $Config->setOrderShopgateMOPIDs(implode('|', $this->Request()->OrderShopgateMOPIDs));
        $Config->setOrderItemTextSyncActionID($this->Request()->OrderItemTextSyncActionID == true ? EXPORT_ORDER_ITEM_TEXT_SYNC : EXPORT_ORDER_ITEM_TEXT_SYNC_NO);
        $Config->setOutgoingItemsOrderStatus($this->Request()->OutgoingItemsOrderStatus);
        $Config->setCheckOutgoingItems($this->Request()->CheckOutgoingItems == true ? 1 : 0);
        $Config->setOutgoingItemsID($this->Request()->OutgoingItemsID);
        $Config->setOutgoingItemsShopwareOrderStatusID($this->Request()->OutgoingItemsShopwareOrderStatusID);
        $Config->setCheckIncomingPayment($this->Request()->CheckIncomingPayment == true ? 1 : 0);
        $Config->setIncomingPaymentShopwarePaymentFullStatusID($this->Request()->IncomingPaymentShopwarePaymentFullStatusID);
        $Config->setIncomingPaymentShopwarePaymentPartialStatusID($this->Request()->IncomingPaymentShopwarePaymentPartialStatusID);
        $Config->setInitialExportChunkSize(max($this->Request()->InitialExportChunkSize, 1));
        $Config->setImportItemChunkSize(max($this->Request()->ImportItemChunkSize, 1));
        $Config->setInitialExportChunksPerRun(max($this->Request()->InitialExportChunksPerRun, -1));
        $Config->setMayLogUsageData($this->Request()->MayLogUsageData == true ? 1 : 0);
        // Customer default values
        $Config->setCustomerDefaultFormOfAddressID($this->Request()->CustomerDefaultFormOfAddressID);
        $Config->setCustomerDefaultCity($this->Request()->CustomerDefaultCity);
        $Config->setCustomerDefaultHouseNumber($this->Request()->CustomerDefaultHouseNumber);
        $Config->setCustomerDefaultStreet($this->Request()->CustomerDefaultStreet);
        $Config->setCustomerDefaultZipcode($this->Request()->CustomerDefaultZipcode);
        //
        if ($Config->getOutgoingItemsIntervalID() != $this->Request()->OutgoingItemsIntervalID) {
            switch ($this->Request()->OutgoingItemsIntervalID) {
                case 1:
                    $nextrun = date('H') > 12 ? strtotime('tomorrow noon') : strtotime('noon');
                    $interval = 68400;
                    break;
                case 2:
                    $nextrun = date('H') > 18 ? strtotime('tomorrow 6pm') : strtotime('6pm');
                    $interval = 68400;
                    break;
                case 3:
                default:
                    $nextrun = strtotime(date('Y-m-d H:0', strtotime('+ 1 hour')));
                    $interval = 60 * 60;
            }
            $Config->setOutgoingItemsIntervalID($this->Request()->OutgoingItemsIntervalID);
            Shopware()->Db()->query('
				UPDATE s_crontab
					SET
						next = FROM_UNIXTIME(' . $nextrun . '),
						`interval` = ' . $interval . '
					WHERE action = "Shopware_CronJob_PlentymarketsOrderImportCron"
			');
        }
        // Check dx status
        PlentymarketsStatus::getInstance()->maySynchronize(false);
        // User settings of the data exchange
        $Config->setMayDatexUser((int) ($this->Request()->MayDatexUser == true));
        // Activate the actual settings if the user
        // wants to exchange data and if he is allowed to
        if ($this->Request()->MayDatexUser == true && $Config->getMayDatex(0)) {
            $Config->setMayDatexActual(1);
        } else {
            $Config->setMayDatexActual(0);
        }
        $config = $Config->getConfig();
        if (isset($config['OrderPaidStatusID'])) {
            $orderPaidIDs = explode('|', $config['OrderPaidStatusID']);
            $config['OrderPaidStatusID'] = array_map('intval', $orderPaidIDs);
        } else {
            $config['OrderPaidStatusID'] = array(12);
        }
        if (isset($config['OrderShopgateMOPIDs'])) {
            $orderShopgateMOPIDs = explode('|', $config['OrderShopgateMOPIDs']);
            $config['OrderShopgateMOPIDs'] = array_map('intval', $orderShopgateMOPIDs);
        } else {
            $config['OrderShopgateMOPIDs'] = array();
        }
        $this->View()->assign(array('success' => true, 'data' => $config));
    }
 /**
  * Prepares config data and checks different conditions like finished mapping.
  */
 protected function __construct()
 {
     //
     $this->Config = PlentymarketsConfig::getInstance();
     $this->StatusController = PlentymarketsExportStatusController::getInstance();
     // Check whether a process is running
     $this->isRunning = (bool) $this->Config->getIsExportRunning(false);
     // If the export is not complete
     if (!$this->isComplete()) {
         // the garbage collector will run
         PlentymarketsGarbageCollector::getInstance()->run(PlentymarketsGarbageCollector::ACTION_MAPPING);
     }
     // Check whether settings and mapping are done
     $this->mayRun = PlentymarketsStatus::getInstance()->mayExport();
 }
/**
 * Shortcut for PlentymarketsStatus::getInstance()
 *
 * @return PlentymarketsStatus
 */
function PyStatus()
{
    return PlentymarketsStatus::getInstance();
}
 /**
  * Checks whether any cronjob may run or not.
  */
 protected function __construct()
 {
     // Check whether any cronjob my be executed due to api status
     $this->Status = PlentymarketsStatus::getInstance();
     $this->Config = PlentymarketsConfig::getInstance();
 }