/** * Saves translation data to the storage. */ public function saveTranslationAction() { $type = (string) $this->Request()->getParam('type'); $merge = (bool) $this->Request()->getParam('merge'); $key = (string) $this->Request()->getParam('key', 1); $language = (string) $this->Request()->getParam('language'); $data = (array) $this->Request()->getParam('data', array()); $this->View()->assign(array('success' => $this->translation->write($language, $type, $key, $data, $merge))); }
private function registerPaymentTranslations() { $translations = (require __DIR__ . '/Translations/Payment.php'); $shops = $this->getTranslationShops(); $module = new Shopware_Components_Translation(); $payment = $this->getStripePayment(); if ($payment !== null) { foreach ($translations as $locale => $translation) { if (isset($shops[$locale])) { $language = $shops[$locale]; $module->write($language, 'config_payment', $payment->getId(), $translation, true); } } } }
/** * @param integer $articleId * @param array $translations * @throws \Shopware\Components\Api\Exception\CustomValidationException */ public function writeTranslations($articleId, $translations) { $whitelist = array( 'name', 'description', 'descriptionLong', 'keywords', 'packUnit' ); $translationWriter = new \Shopware_Components_Translation(); foreach ($translations as $translation) { $shop = $this->getManager()->find('Shopware\Models\Shop\Shop', $translation['shopId']); if (!$shop) { throw new ApiException\CustomValidationException(sprintf("Shop by id %s not found", $translation['shopId'])); } $data = array_intersect_key($translation, array_flip($whitelist)); $translationWriter->write($shop->getId(), 'article', $articleId, $data); } }
/** * Extends all orderMail-templates */ private function _updateOrderMail() { $sql = Shopware()->Db()->select()->from('s_core_config_mails', array('content', 'contentHTML'))->where('`name`=?', array("sORDER")); $orderMail = Shopware()->Db()->fetchRow($sql); $snippets = Shopware()->Db()->select()->from('s_core_snippets', array('shopID', 'value'))->where('`name`=?', array('feedback_info_sepa_date'))->query()->fetchAll(); foreach ($snippets as $snippet) { $additionalContent = '{$additional.payment.additionaldescription}' . "\n" . '{if $additional.payment.name == "paymilldebit"}%BR%' . $snippet['value'] . ': {$paymillSepaDate}' . "\n" . '{/if}' . "\n"; $content = preg_replace('/%BR%/', "\n", $additionalContent); $contentHTML = preg_replace('/%BR%/', "<br/>\n", $additionalContent); if ($snippet['shopID'] === '1' && !preg_match('/\\$paymillSepaDate/', $orderMail['content']) && !preg_match('/\\$paymillSepaDate/', $orderMail['contentHTML'])) { $orderMail['content'] = preg_replace('/\\{\\$additional\\.payment\\.additionaldescription\\}/', $content, $orderMail['content']); $orderMail['contentHTML'] = preg_replace('/\\{\\$additional\\.payment\\.additionaldescription\\}/', $contentHTML, $orderMail['contentHTML']); Shopware()->Db()->update('s_core_config_mails', $orderMail, '`name` LIKE "sORDER"'); } $translationObject = new Shopware_Components_Translation(); $translation = $translationObject->read($snippet['shopID'], "config_mails", 2); if ((array_key_exists('content', $translation) || array_key_exists('content', $translation)) && $snippet['shopID'] !== '1' && !preg_match('/\\$paymillSepaDate/', $translation['content']) && !preg_match('/\\$paymillSepaDate/', $translation['contentHtml'])) { $translation['content'] = preg_replace('/\\{\\$additional\\.payment\\.additionaldescription\\}/', $content, $translation['content']); $translation['contentHtml'] = preg_replace('/\\{\\$additional\\.payment\\.additionaldescription\\}/', $contentHTML, $translation['contentHtml']); $translationObject->write($snippet['shopID'], "config_mails", 2, $translation); } } }
/** * Adds a translation set for the payment with the given key * * @param String $key Key of the payment (numeric) * @param String $description * @param String $additionalDescription (optional) */ public function addPaymentTranslation($key, $description, $additionalDescription = "") { $translationObject = new Shopware_Components_Translation(); $helper = new Shopware_Plugins_Frontend_SofortPayment_Components_Helpers_Helper(); $data = array(); $data['description'] = $description; $data['additionalDescription'] = $additionalDescription; $languages = $helper->database()->getShopIds($this->_language); foreach ($languages as $language) { $translationObject->write($language['id'], "config_payment", $key, $data, 1); } }
/** * @param $records * @throws AdapterException * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\TransactionRequiredException * @throws \Enlight_Event_Exception * @throws \Exception */ public function write($records) { if (empty($records['default'])) { $message = SnippetsHelper::getNamespace()->get('adapters/articlesTranslations/no_records', 'No article translation records were found.'); throw new \Exception($message); } $records = $this->eventManager->filter('Shopware_Components_SwagImportExport_DbAdapters_ArticlesTranslationsDbAdapter_Write', $records, ['subject' => $this]); $whiteList = ['name', 'description', 'descriptionLong', 'metaTitle', 'keywords']; $variantWhiteList = ['additionalText', 'packUnit']; $whiteList = array_merge($whiteList, $variantWhiteList); if (!SwagVersionHelper::isDeprecated('5.3.0')) { $elementBuilder = $this->getElementBuilder(); $legacyAttributes = $elementBuilder->getQuery()->getArrayResult(); if ($legacyAttributes) { foreach ($legacyAttributes as $attr) { $whiteList[] = $attr['name']; $variantWhiteList[] = $attr['name']; } } } $attributes = $this->getAttributes(); if ($attributes) { foreach ($attributes as $attribute) { $whiteList[] = $attribute['columnName']; $variantWhiteList[] = $attribute['columnName']; } } $articleDetailRepository = $this->manager->getRepository(Detail::class); $shopRepository = $this->manager->getRepository(Shop::class); foreach ($records['default'] as $index => $record) { try { $record = $this->validator->filterEmptyString($record); $this->validator->checkRequiredFields($record); $this->validator->validate($record, ArticleTranslationValidator::$mapper); $shop = false; if (isset($record['languageId'])) { $shop = $shopRepository->find($record['languageId']); } if (!$shop) { $message = SnippetsHelper::getNamespace()->get('adapters/articlesTranslations/lang_id_not_found', 'Language with id %s does not exists for article %s'); throw new AdapterException(sprintf($message, $record['languageId'], $record['articleNumber'])); } $articleDetail = $articleDetailRepository->findOneBy(['number' => $record['articleNumber']]); if (!$articleDetail) { $message = SnippetsHelper::getNamespace()->get('adapters/article_number_not_found', 'Article with order number %s doen not exists'); throw new AdapterException(sprintf($message, $record['articleNumber'])); } $articleId = $articleDetail->getArticle()->getId(); if ($articleDetail->getKind() === 1) { $data = array_intersect_key($record, array_flip($whiteList)); $type = 'article'; $objectKey = $articleId; } else { $data = array_intersect_key($record, array_flip($variantWhiteList)); $type = 'variant'; $objectKey = $articleDetail->getId(); } if (!empty($data)) { $data = $this->prepareAttributePrefix($data, $attributes); $this->translationComponent->write($shop->getId(), $type, $objectKey, $data); } } catch (AdapterException $e) { $message = $e->getMessage(); $this->saveMessage($message); } } }
/** * @param $records * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\TransactionRequiredException * @throws \Enlight_Event_Exception * @throws \Exception */ public function write($records) { if (empty($records['default'])) { $message = SnippetsHelper::getNamespace()->get('adapters/translations/no_records', 'No translation records were found.'); throw new \Exception($message); } $records = Shopware()->Events()->filter('Shopware_Components_SwagImportExport_DbAdapters_TranslationsDbAdapter_Write', $records, array('subject' => $this)); $validator = $this->getValidator(); $importMapper = $this->getElementMapper(); $translationWriter = new \Shopware_Components_Translation(); foreach ($records['default'] as $index => $record) { try { $record = $validator->filterEmptyString($record); $validator->checkRequiredFields($record); $validator->validate($record, TranslationValidator::$mapper); if (isset($record['languageId'])) { $shop = $this->getManager()->find(Shop::class, $record['languageId']); } if (!$shop) { $message = SnippetsHelper::getNamespace()->get('adapters/translations/lang_id_not_found', 'Language with id %s does not exists'); throw new AdapterException(sprintf($message, $record['languageId'])); } $repository = $this->getRepository($record['objectType']); if (isset($record['objectKey'])) { $element = $repository->findOneBy(array('id' => (int) $record['objectKey'])); if (!$element) { $message = SnippetsHelper::getNamespace()->get('adapters/translations/element_id_not_found', '%s element not found with ID %s'); throw new AdapterException(sprintf($message, $record['objectType'], $record['objectKey'])); } } elseif (isset($record['baseName'])) { $findKey = $record['objectType'] === 'propertyvalue' ? 'value' : 'name'; $element = $repository->findOneBy(array($findKey => $record['baseName'])); if (!$element) { $message = SnippetsHelper::getNamespace()->get('adapters/translations/element_baseName_not_found', '%s element not found with name %s'); throw new AdapterException(sprintf($message, $record['objectType'], $record['baseName'])); } } if (!$element) { $message = SnippetsHelper::getNamespace()->get('adapters/translations/element_objectKey_baseName_not_found', 'Please provide objectKey or baseName'); throw new AdapterException(sprintf($message)); } $key = $importMapper[$record['objectType']]; $data[$key] = $record['name']; if ($record['objectType'] == 'configuratorgroup') { $data['description'] = $record['description']; } $translationWriter->write($shop->getId(), $record['objectType'], $element->getId(), $data); unset($shop); unset($element); unset($data); } catch (AdapterException $e) { $message = $e->getMessage(); $this->saveMessage($message); } } }