/** * Assigns a specified value to the template. * If no cache or scope given, the default settings for this property will be used. * * @param string $spec * @param mixed $value * @param bool $nocache * @param int $scope * @return \Enlight_View|\Enlight_View_Default */ public function assign($spec, $value = null, $nocache = null, $scope = null) { if ($this->nocache !== null && $nocache === null) { $nocache = $this->nocache; } if ($this->scope !== null && $scope === null) { $scope = $this->scope; } if ($this->template !== null) { $this->template->assign($spec, $value, $nocache, $scope); } else { $this->engine->assign($spec, $value, $nocache); } return $this; }
/** * 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); }
/** * 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); }