[Tep-j-general] Re: ショッピングカートの画面に推売機能を搭載したい

Back to archive index

Seiji Sogabe sogab****@alles*****
2006年 5月 2日 (火) 09:46:18 JST


曽我部です。

koga wrote:
> 当初はalso_purchased_products.phpを何とか改造し、ショッピングカートで使
> 用できるものをと考えたのですが、当方の初歩的な知識では、どうすれば応用で
> きるのか考え付かず、良いContributionがあればと考えています。

shopping_cart.phpでは、61行目でカートにある商品の情報を$productsに取得していますので、
$i番目のproducts_idは、$products[$i]['id']で取得できます。

それが分かれば、also_purchased_products.phpでその商品を買ったオーダーを検索すれば
いいだけだと思います。

詳しく説明するのは難しいので、適当につくったものを以下に示します。
also_purchased_products_cart.php
として、catalog/includes/modulesに保存してください。
あとは、catalog/shopping_cart.phpの表示したいところに、

<?php require(DIR_WS_MODULES. 'also_purchased_products_cart.php'); ?>

を追加と、catalog/includes/languages/japanese/shopping_cart.phpに、

define('TEXT_ALSO_PURCHASED_PRODUCTS', 'こんな商品も買っています');

が必要です。

適当なので、もっといい方法があるかもしれません。

<?php

    $cart_orders = array();
    reset($products);
    foreach ($products as $product) {
        $orders_query = tep_db_query("select p.products_id, p.products_image from " .
TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o,
" . TABLE_PRODUCTS . " p where opa.products_id = '" . (int)$product['id'] . "' and
opa.orders_id = opb.orders_id and opb.products_id != '" . (int)$product['id'] . "' and
opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status =
'1' group by p.products_id order by o.date_purchased desc limit " .
MAX_DISPLAY_ALSO_PURCHASED);
        while ($order = tep_db_fetch_array($orders_query)) {
            if (!in_array($order, $cart_orders)) {
                $cart_orders[] = $order;
            }
        }
    }

    shuffle($cart_orders);
    $num_products_ordered = sizeof($cart_orders);
    if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED) {
?>
<!-- also_purchased_products //-->
<?php

      $info_box_contents = array();
      $info_box_contents[] = array('text' => TEXT_ALSO_PURCHASED_PRODUCTS);

      new contentBoxHeading($info_box_contents);

      $row = 0;
      $col = 0;
      $info_box_contents = array();
      for ($i=0; $i<min($num_products_ordered, MAX_DISPLAY_ALSO_PURCHASED); $i++) {
        $orders = $cart_orders[$i];
        $orders['products_name'] = tep_get_products_name($orders['products_id']);
        $info_box_contents[$row][$col] = array('align' => 'center',
                                               'params' => 'class="smallText" width="33%"
valign="top"',
                                               'text' => '<a href="' .
tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' .
tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'],
SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' .
tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' .
$orders['products_name'] . '</a>');

        $col ++;
        if ($col > 2) {
          $col = 0;
          $row ++;
        }
      }

      new contentBox($info_box_contents);
?>
<!-- also_purchased_products_eof //-->
<?php
    }
?>


-- 
sogab****@alles*****




Tep-j-general メーリングリストの案内
Back to archive index