Exemple #1
0
function _exportAllCategories($f, &$_ProductIDs)
{
    $Cats = array();
    $execCats = array();
    $sql = "\n\t\t\t\t\tSELECT catt.category_id, cdes.category, catt.parent_id FROM cscart_categories catt\n                    LEFT JOIN cscart_category_descriptions cdes on cdes.lang_code=\"RU\" and cdes.category_id=catt.category_id order by catt.parent_id\n\t\t\t\t";
    $q = mysql_query($sql);
    fputs($f, "\t\t<categories>\n");
    while ($row = mysql_fetch_array($q)) {
        if (strlen($row[1]) > 4) {
            if (!in_array($row[0], $execCats)) {
                $execCats[] = $row[0];
            }
            if (!in_array($row[2], $Cats) && $row[2] > 1) {
                $Cats[] = $row[2];
            }
            $row[1] = _deleteHTML_Elements($row[1]);
            if ($row[2] <= 1) {
                fputs($f, "\t\t\t<category id=\"" . $row[0] . "\">" . $row[1] . "</category>\n");
            } else {
                fputs($f, "\t\t\t<category id=\"" . $row[0] . "\" parentId=\"" . $row[2] . "\">" . $row[1] . "</category>\n");
            }
        }
    }
    while (count($Cats)) {
        $sql = "\t\t\t\t\t\t\n                        SELECT catt.category_id, cdes.category, catt.parent_id FROM cscart_categories catt\n                        LEFT JOIN cscart_category_descriptions cdes on cdes.lang_code=\"RU\" and cdes.category_id=catt.category_id order by catt.parent_id\n\t\t\t\t\t\t";
        $q = mysql_query($sql);
        $Cats = array();
        while ($row = mysql_fetch_array($q)) {
            if (strlen($row[1]) > 4) {
                $Disp = false;
                if (!in_array($row[0], $execCats)) {
                    $execCats[] = $row[0];
                    $Disp = true;
                }
                if (!in_array($row[2], $execCats) && !in_array($row[2], $Cats) && $row[2] > 1) {
                    $Cats[] = $row[2];
                }
                $row[1] = _deleteHTML_Elements($row[1]);
                if ($row[2] <= 1 && $Disp) {
                    fputs($f, "\t\t\t<category id=\"" . $row[0] . "\">" . $row[1] . "</category>\n");
                } elseif ($Disp) {
                    fputs($f, "\t\t\t<category id=\"" . $row[0] . "\" parentId=\"" . $row[2] . "\">" . $row[1] . "</category>\n");
                }
            }
        }
    }
    fputs($f, "\t\t</categories>\n");
}
Exemple #2
0
 function _exportProducts($f, $rate, $export_product_name, $categories_select)
 {
     if (!count($categories_select)) {
         return 0;
     }
     include_once "core/classes/class.html2text.php";
     include_once "core/classes/class.htmlparser.php";
     fputs($f, "  <offers>\n");
     //товары с нулевым остатком на складе
     if (isset($_POST["yandex_dont_export_negative_stock"])) {
         $clause = " and in_stock>0";
     } else {
         $clause = "";
     }
     //какое описание экспортировать
     if ($_POST["yandex_export_description"] == 1) {
         $dsc = "description";
         $dsc_q = ", " . $dsc;
     } else {
         if ($_POST["yandex_export_description"] == 2) {
             $dsc = "brief_description";
             $dsc_q = ", " . $dsc;
         } else {
             $dsc = "";
             $dsc_q = "";
         }
     }
     $clause .= " and categoryID IN (" . implode(", ", xEscSQL($categories_select)) . ")";
     $sql = '
     SELECT
     productID,
     name,
     Price,
     categoryID,
     default_picture' . $dsc_q . ',
     in_stock,
     uri,
     uri_opt_val
     ' . convert_prices() . '
     FROM ' . PRODUCTS_TABLE . '
     WHERE enabled=1' . $clause;
     $q = db_query($sql);
     $store_url = correct_URL(CONF_FULL_SHOP_URL);
     while ($product = db_fetch_row($q)) {
         $price_row = priceRow($product);
         $url = $store_url . fu_make_url($product);
         fputs($f, " <offer available=\"" . ($product['in_stock'] || !CONF_CHECKSTOCK ? 'true' : 'false') . "\" id=\"" . $product["productID"] . "\">\n");
         fputs($f, "   <url>" . $url . "</url>\n");
         //fputs($f, "   <price>" . roundf($product["Price"] * $rate) . "</price>\n");
         fputs($f, "   <price>" . $price_row['Price_base'] . "</price>\n");
         fputs($f, "   <currencyId>RUR</currencyId>\n");
         fputs($f, "   <categoryId>" . $product["categoryID"] . "</categoryId>\n");
         if ($product["default_picture"] != NULL) {
             $pic_clause = " and photoID=" . (int) $product["default_picture"];
         } else {
             $pic_clause = "";
         }
         $q1 = db_query("select filename, thumbnail from " . PRODUCT_PICTURES . " where productID=" . (int) $product["productID"] . $pic_clause);
         $pic_row = db_fetch_row($q1);
         if ($pic_row) {
             if (strlen($pic_row["filename"]) && file_exists("data/small/" . $pic_row["filename"])) {
                 fputs($f, "   <picture>" . $store_url . "data/small/" . str_replace(' ', '%20', _deleteHTML_Elements($pic_row["filename"])) . "</picture>\n");
             } else {
                 if (strlen($pic_row["thumbnail"]) && file_exists("data/medium/" . $pic_row["thumbnail"])) {
                     fputs($f, "   <picture>" . $store_url . "data/medium/" . str_replace(' ', '%20', _deleteHTML_Elements($pic_row["thumbnail"])) . "</picture>\n");
                 }
             }
         }
         switch ($export_product_name) {
             default:
             case 'only_name':
                 $_NameAddi = '';
                 break;
             case 'path_and_name':
                 $_NameAddi = '';
                 $_t = catCalculatePathToCategory($product['categoryID']);
                 foreach ($_t as $__t) {
                     if ($__t['categoryID'] != 1) {
                         $_NameAddi .= $__t['name'] . ':';
                     }
                 }
                 break;
         }
         $product["name"] = _deleteHTML_Elements($_NameAddi . $product["name"]);
         fputs($f, "   <name>" . $product["name"] . "</name>\n");
         if (strlen($dsc) > 0) {
             $product_dsc = new Html2Text($product[$dsc], 10000);
             $product_dsc = $product_dsc->convert();
             fputs($f, "   <description>" . _deleteHTML_Elements($product_dsc) . "</description>\n");
         } else {
             fputs($f, "   <description></description>\n");
         }
         fputs($f, " </offer>\n");
     }
     fputs($f, "  </offers>\n");
 }