[Помощь] Вывод в корзине артикула родительского товара

vicsk

Постоялец
Регистрация
19 Янв 2010
Сообщения
147
Реакции
8
На моем сайте есть доработка: Существуют родительские товары и в них созданы дочерние товары.
Суть запроса в том, чтобы вывести в корзине, у дочерних товаров артикул родительского товара. ID родительского товара известен и передан в корзину путем добавления строки:
Код:
"parent" => $cart_item["parent"],

в функцию (файл ../published/SC/html/scripts/core_functions/cart_functions.php
Код:
function cartGetCartContent(){
    $cart_content     = array();
    $total_price     = 0;
    $freight_cost    = 0;
    $variants         = '';
    $currencyEntry = Currency::getSelectedCurrencyInstance();
    $customerEntry = Customer::getAuthedInstance();
    if(!is_null($customerEntry)){//get cart content from the database
        $q = db_phquery('
            SELECT t3.*, t1.itemID, t1.Quantity, t4.thumbnail FROM ?#SHOPPING_CARTS_TABLE t1
                LEFT JOIN ?#SHOPPING_CART_ITEMS_TABLE t2 ON t1.itemID=t2.itemID
                LEFT JOIN ?#PRODUCTS_TABLE t3 ON t2.productID=t3.productID
                LEFT JOIN ?#PRODUCT_PICTURES t4 ON t3.default_picture=t4.photoID
            WHERE customerID=?', $customerEntry->customerID);
        while ($cart_item = db_fetch_assoc($q)){
            // get variants
            $variants=GetConfigurationByItemId( $cart_item["itemID"] );
            LanguagesManager::ml_fillFields(PRODUCTS_TABLE, $cart_item);
            $costUC = GetPriceProductWithOption( $variants, $cart_item["productID"]);
            $tmp = array(
            "productID" => $cart_item["productID"],
            "slug" => $cart_item["slug"],
            "id" =>    $cart_item["itemID"],
            "name" =>    $cart_item["name"],
            'thumbnail_url' => $cart_item['thumbnail']&&file_exists(DIR_PRODUCTS_PICTURES.'/'.$cart_item['thumbnail'])?URL_PRODUCTS_PICTURES.'/'.$cart_item['thumbnail']:'',
            "brief_description"    =>    $cart_item["brief_description"],
            "quantity"    =>    $cart_item["Quantity"],
            "free_shipping"    =>    $cart_item["free_shipping"],
            "costUC"    =>    $costUC,
            "cost" => show_price($cart_item["Quantity"]*$costUC),
            "product_code" => $cart_item["product_code"],
            "parent" => $cart_item["parent"],
            );
            if($tmp['thumbnail_url']){
                list($thumb_width, $thumb_height) = getimagesize(DIR_PRODUCTS_PICTURES.'/'.$cart_item['thumbnail']);
                list($tmp['thumbnail_width'], $tmp['thumbnail_height']) = shrink_size($thumb_width, $thumb_height, round(CONF_PRDPICT_THUMBNAIL_SIZE/2), round(CONF_PRDPICT_THUMBNAIL_SIZE/2));
            }
            $freight_cost += $cart_item["Quantity"]*$cart_item["shipping_freight"];
            $strOptions=GetStrOptions(GetConfigurationByItemId( $tmp["id"] ));
            if(trim($strOptions) != "")
            $tmp["name"].="  (".$strOptions.")";
            if ( $cart_item["min_order_amount"] > $cart_item["Quantity"] )
            $tmp["min_order_amount"] = $cart_item["min_order_amount"];
            $total_price += $cart_item["Quantity"]*$costUC;
            $cart_content[] = $tmp;
        }
    }else{ //unauthorized user - get cart from session vars
        $total_price     = 0; //total cart value
        $cart_content    = array();
        //shopping cart items count
        if ( isset($_SESSION["gids"]) )
        for ($j=0; $j<count($_SESSION["gids"]); $j++)
        {
            if ($_SESSION["gids"][$j])
            {
                $session_items[] = CodeItemInClient($_SESSION["configurations"][$j], $_SESSION["gids"][$j]);
                $q = db_phquery("SELECT t1.*, p1.thumbnail FROM ?#PRODUCTS_TABLE t1 LEFT JOIN ?#PRODUCT_PICTURES p1 ON t1.default_picture=p1.photoID WHERE t1.productID=?", $_SESSION["gids"][$j]);
                if ($r = db_fetch_row($q)){
                    LanguagesManager::ml_fillFields(PRODUCTS_TABLE, $r);
                    $costUC = GetPriceProductWithOption(
                    $_SESSION["configurations"][$j],
                    $_SESSION["gids"][$j])/* * $_SESSION["counts"][$j]*/;
                    $id = $_SESSION["gids"][$j];
                    if (count($_SESSION["configurations"][$j]) > 0)
                    {
                        for ($tmp1=0;$tmp1<count($_SESSION["configurations"][$j]);$tmp1++) $id .= "_".$_SESSION["configurations"][$j][$tmp1];
                    }
                    $tmp = array(
                    "productID"    =>  $_SESSION["gids"][$j],
                    "slug"    =>  $r['slug'],
                    "id"        =>    $id, //$_SESSION["gids"][$j],
                    "name"        =>    $r['name'],
                    'thumbnail_url' => $r['thumbnail']&&file_exists(DIR_PRODUCTS_PICTURES.'/'.$r['thumbnail'])?URL_PRODUCTS_PICTURES.'/'.$r['thumbnail']:'',
                    "brief_description"    => $r["brief_description"],
                    "quantity"    =>    $_SESSION["counts"][$j],
                    "free_shipping"    =>    $r["free_shipping"],
                    "costUC"    =>    $costUC,
                    "cost"        =>    show_price($costUC * $_SESSION["counts"][$j])
                    );
                    if($tmp['thumbnail_url']){
                        list($thumb_width, $thumb_height) = getimagesize(DIR_PRODUCTS_PICTURES.'/'.$r['thumbnail']);
                        list($tmp['thumbnail_width'], $tmp['thumbnail_height']) = shrink_size($thumb_width, $thumb_height, round(CONF_PRDPICT_THUMBNAIL_SIZE/2), round(CONF_PRDPICT_THUMBNAIL_SIZE/2));
                    }
                    $strOptions=GetStrOptions( $_SESSION["configurations"][$j] );
                    if ( trim($strOptions) != "" )
                    $tmp["name"].="  (".$strOptions.")";
                    $q_product = db_query( "select min_order_amount, shipping_freight from ".PRODUCTS_TABLE.
                    " where productID=".
                    $_SESSION["gids"][$j] );
                    $product = db_fetch_row( $q_product );
                    if ( $product["min_order_amount"] > $_SESSION["counts"][$j] )
                    $tmp["min_order_amount"] = $product["min_order_amount"];
                    $freight_cost += $_SESSION["counts"][$j]*$product["shipping_freight"];
                    $cart_content[] = $tmp;
                    $total_price += GetPriceProductWithOption(
                    $_SESSION["configurations"][$j],
                    $_SESSION["gids"][$j] )*$_SESSION["counts"][$j];
                }
            }
        }
    }
    return array(
    "cart_content"    => $cart_content,
    "total_price"    => $total_price,
    "freight_cost"    => $freight_cost
    );
}
Помогите сделать запрос к базе, который запросит и выведет артикул родительского товара, у товара с ID='$cart_item["parent"]'
 
Назад
Сверху