/** * Test case */ public function testTemplateExists() { $result = $this->manager->templateExists('index.tpl'); $this->assertEquals('success', $result); $result = $this->manager->fetch('string:{if {"index.tpl"|template_exists}}true{/if}'); $this->assertEquals('true', $result); $result = $this->manager->fetch('string:{if {"test.tpl"|template_exists}}true{else}false{/if}'); $this->assertEquals('false', $result); }
/** * Create emotion rewrite rules * * @param null $offset * @param null $limit */ public function sCreateRewriteTableCampaigns($offset = null, $limit = null) { $queryBuilder = $this->modelManager->getRepository('Shopware\\Models\\Emotion\\Emotion')->getListQueryBuilder(); $queryBuilder->andWhere('emotions.isLandingPage = 1 ')->andWhere('emotions.active = 1'); if ($limit !== null && $offset !== null) { $queryBuilder->setFirstResult($offset)->setMaxResults($limit); } $campaigns = $queryBuilder->getQuery()->getArrayResult(); $routerCampaignTemplate = $this->config->get('routerCampaignTemplate'); foreach ($campaigns as $campaign) { $campaign["categoryId"] = null; $this->data->assign('campaign', $campaign); $path = $this->template->fetch('string:' . $routerCampaignTemplate, $this->data); $path = $this->sCleanupPath($path, false); $org_path = 'sViewport=campaign&emotionId=' . $campaign['id']; $this->sInsertUrl($org_path, $path); foreach ($campaign['categories'] as $category) { $campaign["categoryId"] = $category['id']; $this->data->assign('campaign', $campaign); $path = $this->template->fetch('string:' . $routerCampaignTemplate, $this->data); $path = $this->sCleanupPath($path, false); $org_path = 'sViewport=campaign&sCategory=' . $campaign['categoryId'] . '&emotionId=' . $campaign['id']; $this->sInsertUrl($org_path, $path); } } }
/** * Generates and inserts static page urls * * @param $offset * @param $limit */ private function insertStaticPageUrls($offset, $limit) { $shopId = Shopware()->Shop()->getId(); $sitesData = $this->modelManager->getRepository('Shopware\\Models\\Site\\Site')->getSitesWithoutLinkQuery($shopId, $offset, $limit)->getArrayResult(); foreach ($sitesData as $site) { $org_path = 'sViewport=custom&sCustom=' . $site['id']; $this->data->assign('site', $site); $path = $this->template->fetch('string:' . $this->config->get('seoCustomSiteRouteTemplate'), $this->data); $path = $this->sCleanupPath($path, false); $this->sInsertUrl($org_path, $path); } }
/** * Test case */ public function testGetContent() { $resource = new Enlight_Components_Snippet_Resource($this->manager); $this->engine->registerResource('snippet', $resource); $this->assertEquals('test', $this->engine->fetch('snippet:string:{s name="test" namespace="test"}test{/s}')); $this->assertEquals('test', $this->engine->fetch('snippet:string:{namespace name="test"}{s name="test"}test{/s}')); $this->assertEquals('force', $this->engine->fetch('snippet:string:{s name="force" namespace="test" force}force{/s}')); $this->assertEquals('force2', $this->engine->fetch('snippet:string:{s name="force" namespace="test" force}force2{/s}')); $this->assertContains('<span', $this->engine->fetch('snippet:string:{se name="force" namespace="test"}force{/se}')); $this->assertEquals('test', $this->engine->fetch('snippet:string:{namespace name="ignore"}{s name="ignore"}test{/s}')); $this->assertEquals('ignore', $this->engine->fetch('snippet:string:{namespace ignore}{s name="ignore"}ignore{/s}')); }
/** * 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]); } }
/** * executes the current product export * * @param resource $handleResource used as a file or the stdout to fetch the smarty output */ public function executeExport($handleResource) { fwrite($handleResource, $this->sSmarty->fetch('string:' . $this->sSettings['header'], $this->sFeedID)); $context = $this->contextService->getShopContext(); $sql = $this->sCreateSql(); $result = $this->db->query($sql); if ($result === false) { return; } // Update db with the latest values $count = (int) $result->rowCount(); $this->db->update('s_export', array('last_export' => new Zend_Date(), 'cache_refreshed' => new Zend_Date(), 'count_articles' => $count), array('id = ?' => $this->sFeedID)); // fetches all required data to smarty $rows = array(); for ($rowIndex = 1; $row = $result->fetch(); $rowIndex++) { if (!empty($row['group_ordernumber_2'])) { $row['group_ordernumber'] = $this->_decode_line($row['group_ordernumber_2']); $row['group_pricenet'] = explode(';', $row['group_pricenet_2']); $row['group_price'] = explode(';', $row['group_price_2']); $row['group_instock'] = explode(';', $row['group_instock_2']); $row['group_active'] = explode(';', $row['group_active_2']); unset($row['group_ordernumber_2'], $row['group_pricenet_2']); unset($row['group_price_2'], $row['group_instock_2'], $row['group_active_2']); for ($i = 1; $i <= 10; $i++) { if (!empty($row['group_group' . $i])) { $row['group_group' . $i] = $this->_decode_line($row['group_group' . $i]); } else { unset($row['group_group' . $i]); } if (!empty($row['group_option' . $i])) { $row['group_option' . $i] = $this->_decode_line($row['group_option' . $i]); } else { unset($row['group_option' . $i]); } } unset($row['group_additionaltext']); } elseif (!empty($row['group_ordernumber'])) { $row['group_ordernumber'] = $this->_decode_line($row['group_ordernumber']); $row['group_additionaltext'] = $this->_decode_line($row['group_additionaltext']); $row['group_pricenet'] = explode(';', $row['group_pricenet']); $row['group_price'] = explode(';', $row['group_price']); $row['group_instock'] = explode(';', $row['group_instock']); $row['group_active'] = explode(';', $row['group_active']); } if (!empty($row['article_translation_fallback'])) { $translation = $this->sMapTranslation('article', $row['article_translation_fallback']); if ($row['main_detail_id'] != $row['articledetailsID']) { unset($translation['additionaltext']); } $row = array_merge($row, $translation); } if (!empty($row['article_translation'])) { $translation = $this->sMapTranslation('article', $row['article_translation']); if ($row['main_detail_id'] != $row['articledetailsID']) { unset($translation['additionaltext']); } $row = array_merge($row, $translation); } if (!empty($row['detail_translation_fallback'])) { $translation = $this->sMapTranslation('detail', $row['detail_translation_fallback']); $row = array_merge($row, $translation); } if (!empty($row['detail_translation'])) { $translation = $this->sMapTranslation('detail', $row['detail_translation']); $row = array_merge($row, $translation); } $row['name'] = htmlspecialchars_decode($row['name']); $row['supplier'] = htmlspecialchars_decode($row['supplier']); //cast it to float to prevent the division by zero warning $row['purchaseunit'] = floatval($row['purchaseunit']); $row['referenceunit'] = floatval($row['referenceunit']); if (!empty($row['purchaseunit']) && !empty($row['referenceunit'])) { $row['referenceprice'] = Shopware()->Modules()->Articles()->calculateReferencePrice($row['price'], $row['purchaseunit'], $row['referenceunit']); } if ($row['configurator'] > 0) { if (empty($this->sSettings["variant_export"]) || $this->sSettings["variant_export"] == 1) { $row['group_additionaltext'] = array(); if (!empty($row['group_ordernumber'])) { foreach ($row['group_ordernumber'] as $orderNumber) { $product = new StoreFrontBundle\Struct\ListProduct((int) $row['articleID'], (int) $row["articledetailsID"], $orderNumber); $product->setAdditional($row['additionaltext']); $product = $this->additionalTextService->buildAdditionalText($product, $context); if (array_key_exists($orderNumber, $row['group_additionaltext'])) { $row['group_additionaltext'][$orderNumber] = $product->getAdditional(); } if ($orderNumber == $row['ordernumber']) { $row['additionaltext'] = $product->getAdditional(); } } } } $product = new StoreFrontBundle\Struct\ListProduct((int) $row['articleID'], (int) $row["articledetailsID"], $row['ordernumber']); $product->setAdditional($row['additionaltext']); $product = $this->additionalTextService->buildAdditionalText($product, $context); $row['additionaltext'] = $product->getAdditional(); } $rows[] = $row; if ($rowIndex == $count || count($rows) >= 50) { @set_time_limit(30); $this->sSmarty->assign('sArticles', $rows); $rows = array(); $template = 'string:{foreach $sArticles as $sArticle}' . $this->sSettings['body'] . '{/foreach}'; fwrite($handleResource, $this->sSmarty->fetch($template, $this->sFeedID)); } } fwrite($handleResource, $this->sSmarty->fetch('string:' . $this->sSettings['footer'], $this->sFeedID)); fclose($handleResource); }
/** * Fetch an template by name over the Enlight_Template_Manager. * * @param $template_name * @return string */ public function fetch($template_name) { return $this->engine->fetch($template_name, $this->template); }
/** * executes the current product export * * @param resource $handleResource used as a file or the stdout to fetch the smarty output */ public function executeExport($handleResource) { fwrite($handleResource, $this->sSmarty->fetch('string:' . $this->sSettings['header'], $this->sFeedID)); $sql = $this->sCreateSql(); $result = Shopware()->Db()->query($sql); if ($result === false) { return; } // Update db with the latest values $count = (int) $result->rowCount(); Shopware()->Db()->update('s_export', array('last_export' => new Zend_Date(), 'cache_refreshed' => new Zend_Date(), 'count_articles' => $count), array('id = ?' => $this->sFeedID)); // fetches all required data to smarty $rows = array(); for ($rowIndex = 1; $row = $result->fetch(); $rowIndex++) { if (!empty($row['group_ordernumber_2'])) { $row['group_ordernumber'] = $this->_decode_line($row['group_ordernumber_2']); $row['group_pricenet'] = explode(';', $row['group_pricenet_2']); $row['group_price'] = explode(';', $row['group_price_2']); $row['group_instock'] = explode(';', $row['group_instock_2']); $row['group_active'] = explode(';', $row['group_active_2']); unset($row['group_ordernumber_2'], $row['group_pricenet_2']); unset($row['group_price_2'], $row['group_instock_2'], $row['group_active_2']); for ($i = 1; $i <= 10; $i++) { if (!empty($row['group_group' . $i])) { $row['group_group' . $i] = $this->_decode_line($row['group_group' . $i]); } else { unset($row['group_group' . $i]); } if (!empty($row['group_option' . $i])) { $row['group_option' . $i] = $this->_decode_line($row['group_option' . $i]); } else { unset($row['group_option' . $i]); } } unset($row['group_additionaltext']); } elseif (!empty($row['group_ordernumber'])) { $row['group_ordernumber'] = $this->_decode_line($row['group_ordernumber']); $row['group_additionaltext'] = $this->_decode_line($row['group_additionaltext']); $row['group_pricenet'] = explode(';', $row['group_pricenet']); $row['group_price'] = explode(';', $row['group_price']); $row['group_instock'] = explode(';', $row['group_instock']); $row['group_active'] = explode(';', $row['group_active']); } if (!empty($row['article_translation'])) { $translation = $this->sMapTranslation('article', $row['article_translation']); $row = array_merge($row, $translation); } elseif (!empty($row['article_translation_fallback'])) { $translation = $this->sMapTranslation('article', $row['article_translation_fallback']); $row = array_merge($row, $translation); } if (!empty($row['detail_translation'])) { $translation = $this->sMapTranslation('detail', $row['detail_translation']); $row = array_merge($row, $translation); } elseif (!empty($row['detail_translation_fallback'])) { $translation = $this->sMapTranslation('detail', $row['detail_translation_fallback']); $row = array_merge($row, $translation); } $row['name'] = htmlspecialchars_decode($row['name']); $row['supplier'] = htmlspecialchars_decode($row['supplier']); //cast it to float to prevent the devision by zero warning $row['purchaseunit'] = floatval($row['purchaseunit']); $row['referenceunit'] = floatval($row['referenceunit']); if (!empty($row['purchaseunit']) && !empty($row['referenceunit'])) { $row['referenceprice'] = Shopware()->Modules()->Articles()->calculateReferencePrice($row['price'], $row['purchaseunit'], $row['referenceunit']); } $rows[] = $row; if ($rowIndex == $count || count($rows) >= 50) { @set_time_limit(30); $this->sSmarty->assign('sArticles', $rows); $rows = array(); $template = 'string:{foreach $sArticles as $sArticle}' . $this->sSettings['body'] . '{/foreach}'; fwrite($handleResource, $this->sSmarty->fetch($template, $this->sFeedID)); } } fwrite($handleResource, $this->sSmarty->fetch('string:' . $this->sSettings['footer'], $this->sFeedID)); fclose($handleResource); }