예제 #1
0
 /**
  * Assign stored translation data.
  */
 public function readTranslationAction()
 {
     $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 = $this->translation->read($language, $type, $key, $merge);
     $this->View()->assign(array('data' => $data, 'success' => true));
 }
예제 #2
0
파일: Article.php 프로젝트: nhp/shopware-4
    /**
     * @param int $id
     * @return array|\Shopware\Models\Article\Article
     * @throws \Shopware\Components\Api\Exception\ParameterMissingException
     * @throws \Shopware\Components\Api\Exception\NotFoundException
     */
    public function getOne($id)
    {
        $this->checkPrivilege('read');

        if (empty($id)) {
            throw new ApiException\ParameterMissingException();
        }

        $builder = $this->getManager()->createQueryBuilder();
        $builder->select(array(
            'article',
            'mainDetail',
            'PARTIAL categories.{id, name}',
            'PARTIAL similar.{id, name}',
            'PARTIAL accessories.{id, name}',
            'images',
            'links',
            'downloads',
            'tax',
            'customerGroups',
            'propertyValues',
            'supplier',
            'mainDetailAttribute',
            'propertyGroup',
            'details',
        ))
        ->from('Shopware\Models\Article\Article', 'article')
        ->leftJoin('article.mainDetail', 'mainDetail')
        ->leftJoin('article.tax', 'tax')
        ->leftJoin('article.categories', 'categories', null, null, 'categories.id')
        ->leftJoin('article.links', 'links')
        ->leftJoin('article.images', 'images')
        ->leftJoin('article.downloads', 'downloads')
        ->leftJoin('article.related', 'accessories')
        ->leftJoin('article.propertyValues', 'propertyValues')
        ->leftJoin('article.similar', 'similar')
        ->leftJoin('article.customerGroups', 'customerGroups')
        ->leftJoin('article.supplier', 'supplier')
        ->leftJoin('article.details', 'details', 'WITH', 'details.kind = 2')
        ->leftJoin('mainDetail.attribute', 'mainDetailAttribute')
        ->leftJoin('article.propertyGroup', 'propertyGroup')
        ->where('article.id = ?1')
        ->andWhere('images.parentId IS NULL')
        ->setParameter(1, $id);

        /** @var $article \Shopware\Models\Article\Article */
        $article = $builder->getQuery()->getOneOrNullResult($this->getResultMode());

        if (!$article) {
            throw new ApiException\NotFoundException("Article by id $id not found");
        }

        if ($this->getResultMode() == self::HYDRATE_ARRAY) {
            $query = $this->getManager()->createQuery('SELECT shop FROM Shopware\Models\Shop\Shop as shop');
            $shops = $query->getArrayResult();

            $translationReader = new \Shopware_Components_Translation();
            foreach ($shops as $shop) {
                $translation = $translationReader->read($shop['id'], 'article', $id);
                if (!empty($translation)) {
                    $translation['shopId'] = $shop['id'];
                    $article['translations'][$shop['id']] = $translation;
                }
            }
        }

        return $article;
    }
예제 #3
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);
         }
     }
 }
예제 #5
0
파일: Document.php 프로젝트: nhp/shopware-4
	/**
	 * 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]);
		}

	}
예제 #6
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));
 }
예제 #7
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;
 }
예제 #8
0
 /**
  * @param int $id
  * @param array $options
  * @throws \Shopware\Components\Api\Exception\NotFoundException
  * @throws \Shopware\Components\Api\Exception\ParameterMissingException
  * @return array|\Shopware\Models\Article\Article
  */
 public function getOne($id, array $options = [])
 {
     $this->checkPrivilege('read');
     if (empty($id)) {
         throw new ApiException\ParameterMissingException();
     }
     $builder = $this->getManager()->createQueryBuilder();
     $builder->select(['article', 'mainDetail', 'mainDetailPrices', 'tax', 'propertyValues', 'configuratorOptions', 'supplier', 'priceCustomGroup', 'mainDetailAttribute', 'propertyGroup', 'customerGroups'])->from('Shopware\\Models\\Article\\Article', 'article')->leftJoin('article.mainDetail', 'mainDetail')->leftJoin('mainDetail.prices', 'mainDetailPrices')->leftJoin('mainDetailPrices.customerGroup', 'priceCustomGroup')->leftJoin('article.tax', 'tax')->leftJoin('article.propertyValues', 'propertyValues')->leftJoin('article.supplier', 'supplier')->leftJoin('mainDetail.attribute', 'mainDetailAttribute')->leftJoin('mainDetail.configuratorOptions', 'configuratorOptions')->leftJoin('article.propertyGroup', 'propertyGroup')->leftJoin('article.customerGroups', 'customerGroups')->where('article.id = ?1')->setParameter(1, $id);
     /** @var $article \Shopware\Models\Article\Article */
     $article = $builder->getQuery()->getOneOrNullResult($this->getResultMode());
     if (!$article) {
         throw new ApiException\NotFoundException("Article by id {$id} not found");
     }
     if ($this->getResultMode() == self::HYDRATE_ARRAY) {
         /** @var $article array */
         $article['images'] = $this->getArticleImages($id);
         $article['configuratorSet'] = $this->getArticleConfiguratorSet($id);
         $article['links'] = $this->getArticleLinks($id);
         $article['downloads'] = $this->getArticleDownloads($id);
         $article['categories'] = $this->getArticleCategories($id);
         $article['similar'] = $this->getArticleSimilar($id);
         $article['related'] = $this->getArticleRelated($id);
         $article['details'] = $this->getArticleVariants($id);
         $article['seoCategories'] = $this->getArticleSeoCategories($id);
         if (isset($options['considerTaxInput']) && $options['considerTaxInput']) {
             $article['mainDetail']['prices'] = $this->getTaxPrices($article['mainDetail']['prices'], $article['tax']['tax']);
             foreach ($article['details'] as &$detail) {
                 $detail['prices'] = $this->getTaxPrices($detail['prices'], $article['tax']['tax']);
             }
         }
         $query = $this->getManager()->createQuery('SELECT shop FROM Shopware\\Models\\Shop\\Shop as shop');
         $shops = $query->getArrayResult();
         $translationReader = new \Shopware_Components_Translation();
         foreach ($shops as $shop) {
             $translation = $translationReader->read($shop['id'], 'article', $id);
             if (!empty($translation)) {
                 $translation['shopId'] = $shop['id'];
                 $article['translations'][$shop['id']] = $translation;
             }
         }
         if (isset($options['language']) && !empty($options['language'])) {
             /**@var $shop Shop */
             $shop = $this->findEntityByConditions('Shopware\\Models\\Shop\\Shop', [['id' => $options['language']], ['shop' => $options['language']]]);
             $article = $this->translateArticle($article, $shop);
         }
     }
     return $article;
 }
예제 #9
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]);
     }
 }