Exemplo n.º 1
0
 /**
  * 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)));
 }
Exemplo n.º 2
0
 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);
             }
         }
     }
 }
Exemplo n.º 3
0
    /**
     * @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);
        }
    }
Exemplo n.º 4
0
 /**
  * Internal helper function which insert the order detail association data into the passed data array
  * @param array $data
  * @return array
  */
 private function getPositionAssociatedData($data)
 {
     //checks if the status id for the position is passed and search for the assigned status model
     if ($data['statusId'] >= 0) {
         $data['status'] = Shopware()->Models()->find('Shopware\\Models\\Order\\DetailStatus', $data['statusId']);
     } else {
         unset($data['status']);
     }
     //checks if the tax id for the position is passed and search for the assigned tax model
     if (!empty($data['taxId'])) {
         $tax = Shopware()->Models()->find('Shopware\\Models\\Tax\\Tax', $data['taxId']);
         if ($tax instanceof \Shopware\Models\Tax\Tax) {
             $data['tax'] = $tax;
             $data['taxRate'] = $tax->getTax();
         }
     } else {
         unset($data['tax']);
     }
     $articleDetails = null;
     // Add articleId if it's not provided by the client
     if ($data['articleId'] == 0 && !empty($data['articleNumber'])) {
         $detailRepo = Shopware()->Models()->getRepository('Shopware\\Models\\Article\\Detail');
         /** @var \Shopware\Models\Article\Detail $articleDetails */
         $articleDetails = $detailRepo->findOneBy(array('number' => $data['articleNumber']));
         if ($articleDetails) {
             $data['articleId'] = $articleDetails->getArticle()->getId();
         }
     }
     if (!$articleDetails && $data['articleId']) {
         /** @var \Shopware\Models\Article\Detail $articleDetails */
         $articleDetails = Shopware()->Models()->getRepository('Shopware\\Models\\Article\\Detail')->findOneBy(array('number' => $data['articleNumber']));
     }
     //Load ean, unit and pack unit (translate if needed)
     if ($articleDetails) {
         $data['ean'] = $articleDetails->getEan() ?: $articleDetails->getArticle()->getMainDetail()->getEan();
         $unit = $articleDetails->getUnit() ?: $articleDetails->getArticle()->getMainDetail()->getUnit();
         $data['unit'] = $unit ? $unit->getName() : null;
         $data['packunit'] = $articleDetails->getPackUnit() ?: $articleDetails->getArticle()->getMainDetail()->getPackUnit();
         $languageData = Shopware()->Db()->fetchRow('SELECT s_core_shops.default, s_order.language AS languageId
             FROM s_core_shops
             INNER JOIN s_order ON s_order.language = s_core_shops.id
             WHERE s_order.id = :orderId
             LIMIT 1', array('orderId' => $data['orderId']));
         if (!$languageData['default']) {
             $translator = new Shopware_Components_Translation();
             // Translate unit
             if ($unit) {
                 $unitTranslation = $translator->read($languageData['languageId'], 'config_units', 1);
                 if (!empty($unitTranslation[$unit->getId()]['description'])) {
                     $data['unit'] = $unitTranslation[$unit->getId()]['description'];
                 } elseif ($unit) {
                     $data['unit'] = $unit->getName();
                 }
             }
             $articleTranslation = array();
             // Load variant translations if we are adding a variant to the order
             if ($articleDetails->getId() != $articleDetails->getArticle()->getMainDetail()->getId()) {
                 $articleTranslation = $translator->read($languageData['languageId'], 'variant', $articleDetails->getId());
             }
             // Load article translations if we are adding a main article or the variant translation is incomplete
             if ($articleDetails->getId() == $articleDetails->getArticle()->getMainDetail()->getId() || empty($articleTranslation['packUnit'])) {
                 $articleTranslation = $translator->read($languageData['languageId'], 'article', $articleDetails->getArticle()->getId());
             }
             if (!empty($articleTranslation['packUnit'])) {
                 $data['packUnit'] = $articleTranslation['packUnit'];
             }
         }
     }
     return $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);
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Get translations for country states in the current shop language
  * Also includes fallback translations
  * Used internally in sAdmin
  *
  * @param null $state
  * @return array States translations
  */
 public function sGetCountryStateTranslation($state = null)
 {
     if (Shopware()->Shop()->get('skipbackend')) {
         return empty($state) ? array() : $state;
     }
     $languageId = $this->contextService->getShopContext()->getShop()->getId();
     $fallbackId = $this->contextService->getShopContext()->getShop()->getFallbackId();
     $translator = new Shopware_Components_Translation();
     $translationData = $translator->readBatchWithFallback($languageId, $fallbackId, 'config_country_states');
     if (empty($state)) {
         return $translationData;
     }
     if ($translationData[$state["id"]]) {
         $state["statename"] = $translationData[$state["id"]]["name"];
     }
     return $state;
 }
Exemplo n.º 7
0
	/**
	 * Load template / document configuration (s_core_documents / s_core_documents_box)
	 * @access public
	 */
	protected function loadConfiguration4x(){
		$id = $this->_typID;

		$this->_document = new ArrayObject(Shopware()->Db()->fetchRow("
		SELECT * FROM s_core_documents WHERE id = ?
		",array($id),ArrayObject::ARRAY_AS_PROPS));


		// Load Containers
		$this->_document->containers = new ArrayObject(Shopware()->Db()->fetchAll("
		SELECT * FROM s_core_documents_box WHERE documentID = ?
		",array($id),ArrayObject::ARRAY_AS_PROPS));

		$translationComponent = new Shopware_Components_Translation();

		$translation = $translationComponent->read($this->_order->order->language, 'documents', 1);
		
		foreach ($this->_document->containers as $key => $container){

			if (!is_numeric($key)) continue;
			if (!empty($translation[$id][$container["name"]."_Value"])){
				$this->_document->containers[$key]["value"] = $translation[$id][$container["name"]."_Value"];
			}
			if (!empty($translation[$id][$container["name"]."_Style"])){
				$this->_document->containers[$key]["style"] = $translation[$id][$container["name"]."_Style"];
			}
			$this->_document->containers[$container["name"]] = $this->_document->containers[$key];
			unset($this->_document->containers[$key]);
		}

	}
Exemplo n.º 8
0
 /**
  * Creates the deny or allow mail from the db and assigns it to
  * the view.
  *
  * @public
  * @return bool
  */
 public function requestMerchantFormAction()
 {
     $customerGroup = (string) $this->Request()->getParam('customerGroup');
     $userId = (int) $this->Request()->getParam('id');
     $mode = (string) $this->Request()->getParam('mode');
     if ($mode === 'allow') {
         $tplMail = 'sCUSTOMERGROUP%sACCEPTED';
     } else {
         $tplMail = 'sCUSTOMERGROUP%sREJECTED';
     }
     $tplMail = sprintf($tplMail, $customerGroup);
     $builder = $this->container->get('models')->createQueryBuilder();
     $builder->select(array('customer.email', 'customer.languageId'))->from('Shopware\\Models\\Customer\\Customer', 'customer')->where('customer.id = ?1')->setParameter(1, $userId);
     $customer = $builder->getQuery()->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
     if (empty($customer) || empty($customer['email'])) {
         $this->View()->assign(array('success' => false, 'message' => $this->container->get('snippets')->getNamespace('backend/widget/controller')->get('merchantNoUserId', 'There is no user for the specific user id')));
         return false;
     }
     /** @var \Shopware\Models\Mail\Mail $mailModel */
     $mailModel = $this->getModelManager()->getRepository('Shopware\\Models\\Mail\\Mail')->findOneBy(array('name' => $tplMail));
     if (empty($mailModel)) {
         $this->View()->assign(array('success' => true, 'data' => array('content' => '', 'fromMail' => '{config name=mail}', 'fromName' => '{config name=shopName}', 'subject' => '', 'toMail' => $customer['email'], 'userId' => $userId, 'status' => $mode === 'allow' ? 'accepted' : 'rejected')));
         return true;
     }
     $translationReader = new Shopware_Components_Translation();
     $translation = $translationReader->read($customer['languageId'], 'config_mails', $mailModel->getId());
     $mailModel->setTranslation($translation);
     $mailData = array('content' => nl2br($mailModel->getContent()) ?: '', 'fromMail' => $mailModel->getFromMail() ?: '{config name=mail}', 'fromName' => $mailModel->getFromName() ?: '{config name=shopName}', 'subject' => $mailModel->getSubject(), 'toMail' => $customer['email'], 'userId' => $userId, 'status' => $mode === 'allow' ? 'accepted' : 'rejected');
     $this->View()->assign(array('success' => true, 'data' => $mailData));
 }
Exemplo n.º 9
0
 /**
  * translates the dispatch fields
  *
  * @param array $dispatch
  * @param int $languageId
  * @return array
  */
 private function translateDispatch(array $dispatch, $languageId)
 {
     $translation = new Shopware_Components_Translation();
     $dispatchTranslations = $translation->read($languageId, 'config_dispatch');
     $dispatchId = $dispatch['id'];
     if (!is_null($dispatchTranslations[$dispatchId]['dispatch_name'])) {
         $dispatch['name'] = $dispatchTranslations[$dispatchId]['dispatch_name'];
         $dispatch['dispatch_name'] = $dispatchTranslations[$dispatchId]['dispatch_name'];
     }
     $dispatch['description'] = $dispatchTranslations[$dispatchId]['description'];
     return $dispatch;
 }
Exemplo n.º 10
0
 /**
  * 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);
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Load template / document configuration (s_core_documents / s_core_documents_box)
  */
 protected function loadConfiguration4x()
 {
     $id = $this->_typID;
     $this->_document = new ArrayObject(Shopware()->Db()->fetchRow("SELECT * FROM s_core_documents WHERE id = ?", array($id), \PDO::FETCH_ASSOC));
     // Load Containers
     $containers = Shopware()->Db()->fetchAll("SELECT * FROM s_core_documents_box WHERE documentID = ?", array($id), \PDO::FETCH_ASSOC);
     $translation = $this->translationComponent->read($this->_order->order->language, 'documents', 1);
     $this->_document->containers = new ArrayObject();
     foreach ($containers as $key => $container) {
         if (!is_numeric($key)) {
             continue;
         }
         if (!empty($translation[$id][$container["name"] . "_Value"])) {
             $containers[$key]["value"] = $translation[$id][$container["name"] . "_Value"];
         }
         if (!empty($translation[$id][$container["name"] . "_Style"])) {
             $containers[$key]["style"] = $translation[$id][$container["name"] . "_Style"];
         }
         // parse smarty tags
         $containers[$key]['value'] = $this->_template->fetch('string:' . $containers[$key]['value']);
         $this->_document->containers->offsetSet($container["name"], $containers[$key]);
     }
 }