Attributes in Shopping Cart


english 2173
This extension is designed for W3-osCommerce version. But you can also use it for other versions. To do this, the CSS classes in divs must be adapted.

Find in: catalog/shopping_cart.php
    $any_out_of_stock = 0;
      $products = $cart->get_products();
      for ($i=0, $n=sizeof($products); $i<$n; $i++) {
          // Push all attributes information in an array
          if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
              while (list($option, $value) = each($products[$i]['attributes'])) {
                  echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
                  $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
                                      from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                                      where pa.products_id = '" . (int)$products[$i]['id'] . "'
                                       and pa.options_id = '" . (int)$option . "'
                                       and pa.options_id = popt.products_options_id
                                       and pa.options_values_id = '" . (int)$value . "'
                                       and pa.options_values_id = poval.products_options_values_id
                                       and popt.language_id = '" . (int)$languages_id . "'
                                       and poval.language_id = '" . (int)$languages_id . "'");
                  $attributes_values = tep_db_fetch_array($attributes);

                  $products[$i][$option]['products_options_name'] = $attributes_values['products_options_name'];
                  $products[$i][$option]['options_values_id'] = $value;
                  $products[$i][$option]['products_options_values_name'] = $attributes_values['products_options_values_name'];
                  $products[$i][$option]['options_values_price'] = $attributes_values['options_values_price'];
                  $products[$i][$option]['price_prefix'] = $attributes_values['price_prefix'];
              }
          }
      }

Change to:

    $any_out_of_stock = 0;
    $products = $cart->get_products();
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
// Push all attributes information in an array
      if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
        foreach($products[$i]['attributes'] as $option => $value) {
          echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
          $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, poval.products_options_values_id, pa.options_values_price, pa.price_prefix
                                      from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                                      where pa.products_id = '" . (int)$products[$i]['id'] . "'
                                       and pa.options_id = '" . (int)$option . "'
                                       and pa.options_id = popt.products_options_id
                                       and pa.options_values_id = poval.products_options_values_id
                                       and popt.language_id = '" . (int)$languages_id . "'
                                       and popt.options_status = '0'
                                       and poval.language_id = '" . (int)$languages_id . "' order by pa.attribute_sort, popt.options_sort");
                                      
          $products[$i][$option]['form_name'] = 'id[' . $products[$i]['id'] . '][' . $option . ']';
          $products[$i][$option]['selected_id'] = $value;
         
          while($attributes_values = tep_db_fetch_array($attributes)){
              $products[$i][$option]['products_options_name'] = $attributes_values['products_options_name'];

          if ($attributes_values['options_values_price'] != '0') {
              $products[$i][$option]['products_options_values_name'][] = array('id' => $attributes_values['products_options_values_id'],
                                                                             'text' => $attributes_values['products_options_values_name'] .
                                                                                ' ' . $attributes_values['price_prefix'] . ' ' . $currencies->display_price($attributes_values['options_values_price'], tep_get_tax_rate($products[$i]['tax_class_id']))
                                                                             );
          }else{
              $products[$i][$option]['products_options_values_name'][] = array('id' => $attributes_values['products_options_values_id'], 'text' => $attributes_values['products_options_values_name']);
          }
              $products[$i][$option]['options_values_price'][] = $attributes_values['options_values_price'];
              $products[$i][$option]['price_prefix'][] = $attributes_values['price_prefix'];
          }

        }
      }
    }

    $sca_products = $cart->get_products();
    for ($i=0, $n=sizeof($sca_products); $i<$n; $i++) {
// Push all attributes information in an array
      if (isset($sca_products[$i]['attributes']) && is_array($sca_products[$i]['attributes'])) {
        foreach($sca_products[$i]['attributes'] as $sca_option => $sca_value) {
          echo tep_draw_hidden_field('id[' . $sca_products[$i]['id'] . '][' . $sca_option . ']', $sca_value);
          $sca_attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
                                      from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                                      where pa.products_id = '" . (int)$sca_products[$i]['id'] . "'
                                       and pa.options_id = '" . (int)$sca_option . "'
                                       and pa.options_id = popt.products_options_id
                                       and pa.options_values_id = '" . (int)$sca_value . "'
                                       and pa.options_values_id = poval.products_options_values_id
                                       and popt.language_id = '" . (int)$languages_id . "'
                                       and popt.options_status = '0'
                                       and poval.language_id = '" . (int)$languages_id . "'");
          $sca_attributes_values = tep_db_fetch_array($sca_attributes);

          $sca_products[$i][$sca_option]['products_options_name'] = $sca_attributes_values['products_options_name'];
          $sca_products[$i][$sca_option]['options_values_id'] = $sca_value;
          $sca_products[$i][$sca_option]['products_options_values_name'] = $sca_attributes_values['products_options_values_name'];
          $sca_products[$i][$sca_option]['options_values_price'] = $sca_attributes_values['options_values_price'];
          $sca_products[$i][$sca_option]['price_prefix'] = $sca_attributes_values['price_prefix'];
        }
      }
    }

Find:
ATTENTION! THIS IST THE OLD CODE FOR PHP 7

        if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
            reset($products[$i]['attributes']);
            while (list($option, $value) = each($products[$i]['attributes'])) {
                $products_name .= '<br /><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
            }
        }

or:
ATTENTION! THIS IST THE NEW CODE FOR PHP 8

        if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
            reset($products[$i]['attributes']);
            foreach($sca_products[$i]['attributes'] as $sca_option => $sca_value) {
                $products_name .= '<br /><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
            }
        }

Change to:

if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
reset($products[$i]['attributes']);
if ($products[$i]['status'] > 0){
$originalimgString = $products[$i]['name'];
$outputimgString = preg_replace('/s+/', '', $originalimgString);

$products_name .= '
<span type="button" class="pointer btn btn-info btn-xs w3-border w3-border-black" data-toggle="collapse" data-target="#' . $outputimgString . '">' . TEXT_INFO_PRODUCTS_LISTING_ATTRIBUTE . '</span><div id="' . $outputimgString . '" class="collapse">';
$products_name .= '<div class="mb-2 w3-padding w3-pale-red w3-round"><b><i class="fa fa-sync-alt"></i></b> '. INFO_TEXT_FOR_UPDATE_SHOPPING_CART_ATTRIBUTE . '</div>';
$products_name .= '<div class="mt-2 w3-bottombar w3-topbar w3-border-blue w3-padding-small w3-pale-blue w3-round"><div class="clearfix"></div>';
$products_name .= '<div class="mt-2 w3-border-bottom w3-border-blue">';
$products_name .= '<div class="mt-2 w3-border-bottom w3-border-blue w3-text-red"><div class="mb-2"><b>' . TEXT_INFO_PRODUCTS_LISTING_ATTRIBUTE . ' - ' . $products[$i]['name'] . '</b><span class="pull-right"><button class="btn btn-info w3-border w3-border-black"><b><i class="fa fa-sync-alt"></i></b></button></span><div class="clearfix"></div></div></div>';
$products_name .= '</div>';
foreach($products[$i]['attributes'] as $option => $value) {
if (!empty($products[$i][$option]['products_options_values_name'])) {
$products_name .= '<div class="mt-1 mb-1"><b>' . $products[$i][$option]['products_options_name'] . '</b>' . tep_draw_pull_down_menu($products[$i][$option]['form_name'], $products[$i][$option]['products_options_values_name'], $products[$i][$option]['selected_id']) . '</div>';
  }
}
$products_name .= '<div class="mt-2 mb-2"><button class="btn btn-info w3-border w3-border-black btn-block">&nbsp;<i class="fa fa-sync-alt"></i>&nbsp;' . IMAGE_BUTTON_UPDATE_CART . '&nbsp;</button></div>';
$products_name .= '</div></div>';
}
}
/////////////////////////////////////////////////
if (isset($sca_products[$i]['attributes']) && is_array($sca_products[$i]['attributes'])) {
reset($sca_products[$i]['attributes']);
foreach($sca_products[$i]['attributes'] as $sca_option => $sca_value) {
  if (!empty($sca_products[$i][$sca_option]['products_options_values_name'])) {
   if ($sca_products[$i][$sca_option]['options_values_price'] == '0'){
          $products_name .= '<div class="mt-1"><small><i>- ' . $sca_products[$i][$sca_option]['products_options_name'] . ' &nbsp;<font color="#da0000">' . $sca_products[$i][$sca_option]['products_options_values_name'] . '</font></i></small></div>';
}else{
          $products_name .= '<div class="mt-1"><small><i> - ' . $sca_products[$i][$sca_option]['products_options_name'] . ' &nbsp;<font color="#da0000">' . $sca_products[$i][$sca_option]['products_options_values_name'] . '</font>&nbsp;(' . $sca_products[$i][$option]['price_prefix'] . ' ' . $currencies->display_price($sca_products[$i][$sca_option]['options_values_price'], tep_get_tax_rate($sca_products[$i]['tax_class_id'])) . ')' . '</i></small></div>';
}
  }else{
          $products_name .= '<div class="mt-1"></div>';
  }
}
}

Add in your language file:
catalog/includes/languages/english/shopping_cart.php

English:

define('IMAGE_BUTTON_UPDATE_CART', 'Update Attributes');
define('TEXT_INFO_PRODUCTS_LISTING_ATTRIBUTE', 'Attributes');
define('INFO_TEXT_FOR_UPDATE_SHOPPING_CART_ATTRIBUTE', 'After choosing, please dont forget to update.');
Why your email address?
If necessary, I will contact you to help you with the implementation.
Your email address will not be made public.
Is this post helpful to you?
There are currently no product reviews.
Information(1)
General information
 Free advertising
Post counter
Current information status:
Categories: 9
Posts: 104
Support pages: 56
Downloads for members: 104
Download counter: 646
Reviews total61
Companies: 26
Support: 28
Information: 7