/** * 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); }
/** * Get article data for sAddArticle * * @param int $id Article ordernumber * @return array|false Article data, or false if none found */ private function getArticleForAddArticle($id) { $sql = "\n SELECT s_articles.id AS articleID, s_articles.main_detail_id, name AS articleName, taxID,\n additionaltext, s_articles_details.shippingfree, laststock, instock,\n s_articles_details.id as articledetailsID, ordernumber,\n s_articles.configurator_set_id\n FROM s_articles, s_articles_details\n WHERE s_articles_details.ordernumber = ?\n AND s_articles_details.articleID = s_articles.id\n AND s_articles.active = 1\n AND (\n SELECT articleID\n FROM s_articles_avoid_customergroups\n WHERE articleID = s_articles.id AND customergroupID = ?\n ) IS NULL\n "; $article = $this->db->fetchRow($sql, array($id, $this->sSYSTEM->sUSERGROUPDATA["id"])); $article = $this->eventManager->filter('Shopware_Modules_Basket_getArticleForAddArticle_FilterArticle', $article, array("id" => $id, 'subject' => $this, "partner" => $this->sSYSTEM->_SESSION["sPartner"])); if (!$article) { return false; } $article = $this->moduleManager->Articles()->sGetTranslation($article, $article['articleID'], "article"); $article = $this->moduleManager->Articles()->sGetTranslation($article, $article['articledetailsID'], "variant"); if ($article['configurator_set_id'] > 0) { $context = $this->contextService->getProductContext(); $product = Shopware()->Container()->get('shopware_storefront.list_product_service')->get($article['ordernumber'], $context); $product = $this->additionalTextService->buildAdditionalText($product, $context); $article['additionaltext'] = $product->getAdditional(); } return $article; }
/** * Get name from a certain article by order number * @param string $orderNumber * @param bool $returnAll return only name or additional data, too * @return string or array */ public function sGetArticleNameByOrderNumber($orderNumber, $returnAll = false) { $article = $this->db->fetchRow("\n SELECT\n s_articles.id,\n s_articles.main_detail_id,\n s_articles_details.id AS did,\n s_articles.name AS articleName,\n additionaltext,\n s_articles.configurator_set_id\n FROM s_articles_details, s_articles\n WHERE ordernumber = :orderNumber\n AND s_articles.id = s_articles_details.articleID\n ", array('orderNumber' => $orderNumber)); if (!$article) { return false; } // Load translations for article or variant if ($article['did'] != $article['main_detail_id']) { $article = $this->sGetTranslation($article, $article['did'], "variant"); } else { $article = $this->sGetTranslation($article, $article['id'], "article"); } // If article has variants, we need to append the additional text to the name if ($article['configurator_set_id'] > 0) { $product = new StoreFrontBundle\Struct\ListProduct((int) $article['id'], (int) $article["did"], $orderNumber); $product->setAdditional($article['additionaltext']); $context = $this->contextService->getShopContext(); $product = $this->additionalTextService->buildAdditionalText($product, $context); if (!$returnAll) { return $article["articleName"] . ' ' . $product->getAdditional(); } $article['additionaltext'] = $product->getAdditional(); } if (!$returnAll) { return $article["articleName"]; } return $article; }