Anleitung "Komfortabler Warenkorb"

© 2008 Estelco

(no warranty) released under GPL

1. BACKUP MACHEN!!!

2. Folgende Dateien kopieren

templates/xtc4/img/alter.gif
templates/xtc4/img/delete.gif
templates/xtc4/img/minus.gif
templates/xtc4/img/plus.gif

3. Anpassungen Stylesheet

templates/TEMPLATE/stylesheet.css

Am Ende anfügen

.alter {
display: block;
background-image: url(img/alter.gif);
background-repeat: no-repeat;
width: 13px;
height: 13px;
border: 0px;
font-size: 0px;
cursor: pointer;
}

4. Anpassungen für Dateien:

shopping_cart.php

ca. Zeile 118

                $smarty->assign('min_order', $max_order);
            }
        }
    }

danach einfügen:

    $special_query = xtc_db_query("SELECT p.products_id, pd.products_name, p.products_image, p.products_tax_class_id, p.products_price
                                   FROM products_to_categories ptc, categories_description cd, products p, products_description pd
                                   WHERE cd.categories_name='Warenkorb'
                                   AND cd.language_id=2
                                   AND ptc.categories_id=cd.categories_id
                                   AND p.products_id=ptc.products_id
                                   AND pd.products_id=p.products_id
                                   AND pd.language_id='".$_SESSION['languages_id']."'");

    if (xtc_db_num_rows($special_query)) {
        $module_content = array ();
        while ($special = xtc_db_fetch_array($special_query)) {
            $special_image = '<a href="'.xtc_href_link(basename($PHP_SELF), xtc_get_all_get_params(array ('action')).'action=buy_now&BUYproducts_id='.$special['products_id'], 'NONSSL').'">'.xtc_image(DIR_WS_THUMBNAIL_IMAGES.$special['products_image'], $special['products_name']).'</a>';
            $special_buy_now = '<a href="'.xtc_href_link(basename($PHP_SELF), xtc_get_all_get_params(array ('action')).'action=buy_now&BUYproducts_id='.$special['products_id'], 'NONSSL').'">'.xtc_image_button('button_buy_now.gif', TEXT_BUY.$special['products_name'].TEXT_NOW).'</a>';
            $module_content[] = array ('SPECIAL_NAME' => $special['products_name'], 'SPECIAL_ID' => $special['products_id'], 'SPECIAL_IMAGE' => $special_image, 'SPECIAL_PRICE' => $xtPrice->xtcGetPrice($special['products_id'], $format = true, 1, $special['products_tax_class_id'], $special['products_price']), 'SPECIAL_BUY_NOW' => $special_buy_now);
        }
    } else {
        $module_content = false;
    }

    $smarty->assign('module_content', $module_content);

includes/cart_actions.php

ca. Zeile 52

case 'update_product' :

      if (is_object($econda))
        $econda->_emptyCart();

      for ($i = 0, $n = sizeof($_POST['products_id']); $i < $n; $i++) {
          if (in_array($_POST['products_id'][$i], (is_array($_POST['cart_delete']) ? $_POST['cart_delete'] : array ()))) {
          $_SESSION['cart']->remove($_POST['products_id'][$i]);

          if (is_object($econda))
            $econda->_delArticle($_POST['products_id'][$i], $_POST['cart_quantity'][$i], $_POST['old_qty'][$i]);

        } else {
          if ($_POST['cart_quantity'][$i] > MAX_PRODUCTS_QTY)
            $_POST['cart_quantity'][$i] = MAX_PRODUCTS_QTY;
          $attributes = ($_POST['id'][$_POST['products_id'][$i]]) ? $_POST['id'][$_POST['products_id'][$i]] : '';

          if (is_object($econda)) {
            $old_quantity = $_SESSION['cart']->get_quantity(xtc_get_uprid($_POST['products_id'][$i], $_POST['id'][$i]));
            $econda->_updateProduct($_POST['products_id'][$i], $_POST['cart_quantity'][$i], $old_quantity);
          }

          $_SESSION['cart']->add_cart($_POST['products_id'][$i], xtc_remove_non_numeric($_POST['cart_quantity'][$i]), $attributes, false);
        }
      }
      xtc_redirect(xtc_href_link($goto, xtc_get_all_get_params($parameters)));
      break;
ersetzen durch
        case 'update_product' :
            $_SESSION['alter'] = false;
            if (isset ($_POST['plus']) && array_sum($_POST['plus']) > 0) {
                foreach($_POST['plus'] as $key => $value) {
                    $attributes = ($_POST['id'][$_POST['products_id'][$key]]) ? $_POST['id'][$_POST['products_id'][$key]] : '';
                    $_SESSION['cart']->add_cart($_POST['products_id'][$key], xtc_remove_non_numeric($_POST['cart_quantity'][$key] + 1), $attributes, false);
                }
            } elseif (isset ($_POST['minus']) && array_sum($_POST['minus']) > 0) {
                foreach($_POST['minus'] as $key => $value) {
                    if ($_POST['cart_quantity'][$key] == '1') {
                        $_SESSION['cart']->remove($_POST['products_id'][$key]);
                    } else {
                        $attributes = ($_POST['id'][$_POST['products_id'][$key]]) ? $_POST['id'][$_POST['products_id'][$key]] : '';
                        $_SESSION['cart']->add_cart($_POST['products_id'][$key], xtc_remove_non_numeric($_POST['cart_quantity'][$key] - 1), $attributes, false);
                    }
                }
            } elseif (isset ($_POST['delete']) && array_sum($_POST['delete']) > 0) {
                foreach($_POST['delete'] as $key => $value) {
                    $_SESSION['cart']->remove($_POST['products_id'][$key]);
                }
            } elseif (isset ($_POST['alter'])) {
                $_SESSION['alter'] = true;
                $_SESSION['alter_prod'] = $_POST['alter'];
            } elseif (isset ($_POST['attributes'])) {
              $temp=explode("-",$_POST['attributes']);
              $prod_id = $temp[0];
              $alt = $temp[1];
              $neu = $temp[2];
              $attr_id = $temp[3];
              $attributes = array($attr_id => $neu); //$_POST['id'][$_POST['products_id'][$prod_id]] : '';
              $_SESSION['cart']->modify_attributes($_POST['products_id'][$prod_id], xtc_remove_non_numeric($_POST['cart_quantity'][$prod_id]), $attributes, false);
            } else {
              for ($i = 0, $n = sizeof($_POST['products_id']); $i < $n; $i++) {
                if (in_array($_POST['products_id'][$i], (is_array($_POST['cart_delete']) ? $_POST['cart_delete'] : array ()))) {
                  $_SESSION['cart']->remove($_POST['products_id'][$i]);

                  if (is_object($econda))
                    $econda->_delArticle($_POST['products_id'][$i], $_POST['cart_quantity'][$i], $_POST['old_qty'][$i]);

                } else {
                  if ($_POST['cart_quantity'][$i] > MAX_PRODUCTS_QTY)
                    $_POST['cart_quantity'][$i] = MAX_PRODUCTS_QTY;
                  $attributes = ($_POST['id'][$_POST['products_id'][$i]]) ? $_POST['id'][$_POST['products_id'][$i]] : '';

                  if (is_object($econda)) {
                    $old_quantity = $_SESSION['cart']->get_quantity(xtc_get_uprid($_POST['products_id'][$i], $_POST['id'][$i]));
                    $econda->_updateProduct($_POST['products_id'][$i], $_POST['cart_quantity'][$i], $old_quantity);
                  }

                  $_SESSION['cart']->add_cart($_POST['products_id'][$i], xtc_remove_non_numeric($_POST['cart_quantity'][$i]), $attributes, false);
                }
              }
            }
            xtc_redirect(xtc_href_link($goto, xtc_get_all_get_params($parameters)));
            break;

includes/classes/class.inputfilter.php

nur für ältere Versionen, die den class.inputfilter.php-Patch noch nicht enthalten bzw. eingespielt haben

ca. Zeile 53

  function process($source) {
    // clean all elements in this array
    if (is_array($source)) {
      foreach ($source as $key => $value)
        // filter element for XSS and other 'bad' code etc.
        $tmp_key = $key;
      unset ($source[$key]);
      $key = $this->remove($this->decode($key));
      if ($key != $tmp_key) {
        return $source;
      } else {
        if (is_string($value))
          $source[$key] = $this->remove($this->decode($value));
      }
      return $source;
      // clean this string
    } else
      if (is_string($source)) {
        // filter source for XSS and other 'bad' code etc.
        return $this->remove($this->decode($source));
        // return parameter as given
      } else
        return $source;
  }
ersetzen durch
    function process($source) {
        // clean all elements in this array
        if (is_array($source)) {
            foreach ($source as $key => $value) {
                // filter element for XSS and other 'bad' code etc.
                $tmp_key = $key;
                unset ($source[$key]);
                $key = $this->remove($this->decode($key));
                if ($key != $tmp_key) {
                    return $source;
                } else {
                    if (is_string($value)) {
                        $source[$key] = $this->remove($this->decode($value));
                    } elseif (is_array($value)) {
                        $source[$key] = $this->process($value);
                    }
                }
            }
            return $source;
            // clean this string
        } else
        if (is_string($source)) {
            // filter source for XSS and other 'bad' code etc.
            return $this->remove($this->decode($source));
            // return parameter as given
        } else
        return $source;
    }

includes/classes/shopping_cart.php

ca. Zeile 136

  function update_quantity($products_id, $quantity = '', $attributes = '') {
davor einfügen
  function modify_attributes($products_id, $qty = '1', $attributes = '', $notify = true) {
    $contemp = array();
    $new_key = '';
    while (list ($key, $value) = each($this->contents)) {
      if ($key === $products_id) {
        $temp=preg_split("(\{|\})",$products_id);
        $new_key = $temp[0];
        for ($i = 1; $i < sizeof($temp); $i=$i+2) {
          if ($attributes[$temp[$i+1]]) {
            $new_key .= "{" . $temp[$i] . "}" . $attributes[$temp[$i+1]];
            $changed_key = $temp[$i];
            $changed_value = $attributes[$temp[$i+1]];
          } else {
            $new_key .= "{" . $temp[$i] . "}" . $temp[$i+1];
          }
        }
        if ($contemp[$new_key]['qty']) {
          $contemp[$new_key]['qty'] += $value['qty'];
        } else {
          $contemp[$new_key] = $value;
          $contemp[$new_key]['attributes'][$changed_key] = $changed_value;
        }
      } else {
        if ($key != $new_key) {
          $contemp[$key] = $value;
        } else {
          $contemp[$key]['qty'] += $value['qty'];
        }
      }
    }
    $this->contents = $contemp;
  }

includes/modules/order_details_cart.php

ca. Zeile 56 (normalerweise mitten in der Zeile)

'BOX_DELETE' => xtc_draw_checkbox_field('cart_delete[]', $products[$i]['id']),
ersetzen durch
'DELETE' => xtc_draw_checkbox_field('cart_delete[]', $products[$i]['id']),
'PLUS' => '<input type="image" name="plus['.$i.']" src="templates/'.CURRENT_TEMPLATE.'/img/plus.gif" />',
'MINUS' => '<input type="image" name="minus['.$i.']" src="templates/'.CURRENT_TEMPLATE.'/img/minus.gif" />',
'BOX_DELETE' => '<input type="image" name="delete['.$i.']" src="templates/'.CURRENT_TEMPLATE.'/img/delete.gif" //>', 

ca. Zeile 69

      if (ATTRIBUTE_STOCK_CHECK == 'true' && STOCK_CHECK == 'true') {
        $attribute_stock_check = xtc_check_stock_attributes($products[$i][$option]['products_attributes_id'], $products[$i]['quantity']);
        if ($attribute_stock_check)
          $_SESSION['any_out_of_stock'] = 1;
      }

      $module_content[$i]['ATTRIBUTES'][] = array ('ID' => $products[$i][$option]['products_attributes_id'], 'MODEL' => xtc_get_attributes_model(xtc_get_prid($products[$i]['id']), $products[$i][$option]['products_options_values_name']), 'NAME' => $products[$i][$option]['products_options_name'], 'VALUE_NAME' => $products[$i][$option]['products_options_values_name'].$attribute_stock_check);
ersetzen durch
        if (ATTRIBUTE_STOCK_CHECK == 'true' && STOCK_CHECK == 'true') {
          $attribute_stock_check = xtc_check_stock_attributes($products[$i][$option]['products_attributes_id'], $products[$i]['quantity']);
          if ($attribute_stock_check)
            $_SESSION['any_out_of_stock'] = 1;
        }
            if ($_SESSION['alter'] && $_SESSION['alter_prod']==$i."-".$option) {
                $_SESSION['alter'] = false;
                unset($_SESSION['alter_prod']);
                $temp=preg_split("(\{|\})",$products[$i]['id']);
                $products_id=$temp[0];
                for ($j = 1; $j<sizeof($temp); $j=$j+2) {
                  if ($option == (int) $temp[$j]) {
                    $opt = (int) $temp[$j+1];
                  }
                }
                $attr_query=xtc_db_query("SELECT products_options_values_id,products_options_values_name FROM ". TABLE_PRODUCTS_OPTIONS_VALUES." pov, ".TABLE_PRODUCTS_ATTRIBUTES." pa
                                        WHERE pa.products_id = ".$products_id."
                                        AND pa.options_values_id = pov.products_options_values_id
                                        AND pov.language_id = ". $_SESSION['languages_id'] ."
                                        AND pa.options_id = " . $option . "
                                        ORDER BY pov.products_options_values_id");

                $select='<select name="attributes" onChange="this.form.submit()">';

                while ($attr_res=xtc_db_fetch_array($attr_query)) {
                    $selected=$products[$i]['attributes'][$option]==$attr_res['products_options_values_id']?' selected="selected"':'';
                    $select.='<option value="'.$i.'-'.$products[$i]['attributes'][$option].'-'.$attr_res['products_options_values_id'].'-'.$opt.'"'.$selected.'>'.$attr_res['products_options_values_name'].'</option>';
                } //EOWHILE

                $select.='</select>';
                $module_content[$i]['ATTRIBUTES'][]=array(
                'ID' =>$products[$i][$option]['products_attributes_id'],
                'MODEL'=>xtc_get_attributes_model(xtc_get_prid($products[$i]['id']), $products[$i][$option]['products_options_values_name'],$products[$i][$option]['products_options_name']),
                'NAME' => $products[$i][$option]['products_options_name'],
                'VALUE_NAME' => $select, //$products[$i][$option]['products_options_values_name'].$attribute_stock_check,
                'ALTER' => '<input type="submit" name="alter" value="send" class="alter">'
                );
            } else {
                $module_content[$i]['ATTRIBUTES'][]=array(
                'ID' =>$products[$i][$option]['products_attributes_id'],
                'MODEL'=>xtc_get_attributes_model(xtc_get_prid($products[$i]['id']), $products[$i][$option]['products_options_values_name'],$products[$i][$option]['products_options_name']),
                'NAME' => $products[$i][$option]['products_options_name'],
                'VALUE_NAME' => $products[$i][$option]['products_options_values_name'].$attribute_stock_check,
                'ALTER' => '<input type="submit" name="alter" value="' . $i . '-' . $option . '" class="alter">'
                );
            }

templates/xtc4/module/order_details.html

ca. Zeile 6

<td class="main" style="border-bottom: 1px solid; border-color: #cccccc;" align="center"><strong>{#text_qty#}</strong></td>

ersetzen durch:

<td class="main" style="border-bottom: 1px solid; border-color: #cccccc;" align="center" colspan="3"><strong>{#text_qty#}</strong></td>

ca. Zeile 13 + 38

<tr>
  <td colspan="6"></td>
</tr>
ersetzen durch
<tr>
  <td colspan="8"></td>
</tr>

ca. Zeile 18

<td valign="top" class="main" align="center">{$module_data.PRODUCTS_QTY}</td>
ersetzen durch
<td valign="top" class="main" align="center" width="21">{$module_data.MINUS}</td>
<td valign="top" class="main" align="center">{$module_data.PRODUCTS_QTY}</td>
<td valign="top" class="main" align="center" width="21">{$module_data.PLUS}</td>

ca. Zeile 26

<td class="main">{$item_data.NAME}:</td>
<td class="main" align="left">{$item_data.VALUE_NAME}</td>
danach anfügen
<td class="main" align="left" width="1%">{$item_data.ALTER}</td> 

templates/xtc4/module/shopping_cart.php

ca. Zeile 31

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="main"> </td>
  </tr>
  <tr>
    <td>{$MODULE_order_details}</td>
  </tr>
  <tr>
    <td class="main"></td>
  </tr>
</table>
ersetzen durch:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td class="main"> </td>
    </tr>
    <tr>
      <td>{$MODULE_order_details}</td>
    </tr>
    <tr>
      <td class="main">
      {if $module_content}
        <table width="100%" border="0" background="{$tpl_path}images/bg_light_grey.gif" bgcolor="#EDEDED" class="main">
          <tr>
            {foreach name=aussen item=module_data from=$module_content}
              <td align="center">
                <table border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="100%" align="center" background="{$tpl_path}images/bg_light_grey.gif" bgcolor="#EDEDED" class="main"><strong>{$module_data.SPECIAL_NAME}</strong></td>
                  </tr>
                  <tr>
                    <td width="100%" align="center" background="{$tpl_path}images/bg_light_grey.gif" bgcolor="#EDEDED" class="main">{$module_data.SPECIAL_IMAGE}</td>
                  </tr>
                  <tr>
                    <td align="center" background="{$tpl_path}images/bg_light_grey.gif" bgcolor="#EDEDED" class="main" style="padding-top:3px;"><strong>{$module_data.SPECIAL_PRICE}</strong></td>
                  </tr>
                  <tr>
                    <td align="center" background="{$tpl_path}images/bg_light_grey.gif" bgcolor="#EDEDED" class="main">{$module_data.SPECIAL_BUY_NOW}</td>
                  </tr>
                </table>
              </td>
            {/foreach}
          </tr>
        </table>
        {/if}
      </td>
    </tr>
</table>

5. Hinweise für die Promotionartikel im Warenkorb

Für die Promotionartikel bitte eine Kategorie mit dem deutschen Namen "Warenkorb" anlegen, deaktiviert lassen und die gewünschten Artikel darin anlegen oder verlinken.