Удаление товара из корзины без перезагрузки страницы

#
Удаление товара из корзины без перезагрузки страницы
На 5-ой версии делал удаление из краткой корзины на аджаксе, без перезагрузки страницы.
Изменяемая часть ТДС корзины выглядела так...
/* Удаляение товара из корзины */
if (to_str($_GET['action']) == 'ajax_delete_item')
{
   $param = array();
   $param['shop_id'] = $shop_id;
   $param['item_id'] = to_int($_GET['item_id']);

   /* Проверяем наличие пользователя */
   if ($site_users_id != 0)
   {
      $param['user_id'] = $site_users_id;
   }

   $shop->DeleteCart($param);
   
   // Отображаем корзину
   ob_start();
   $shop->ShowCart($shop_id, $site_users_id, to_str($GLOBALS['LA']['xsl_little_cart']));
   $little_cart_html = ob_get_clean();

   echo $little_cart_html;
   exit();
}


вызов скрипта был завязан на онклик...
весь мозг поломал, никак не могу переписать код ТДС под 6-ку...
чтобы использовать тот-же самый скрипт )))
может подсобит кто?

SNN
#
Re: Удаление товара из корзины без перезагрузки страницы
Да, актуальная тема, тоже ищу решение.
#
Re: Удаление товара из корзины без перезагрузки страницы
Необходим jquery плагин accounting

В xsl шаблоне корзины заменяем Шаблон для товара в корзине на этот

   <!-- Шаблон для товара в корзине -->
   <xsl:template match="shop_cart">
      <tr id="item_{shop_item/@id}">
         <td>
            <a href="{shop_item/url}">
               <xsl:value-of disable-output-escaping="yes" select="shop_item/name"/>
            </a>
         </td>
         <td>
            <input type="text" size="3" name="quantity_{shop_item/@id}" id="quantity_{shop_item/@id}" value="{quantity}"/>
         </td>
         <td>
            <!-- Цена -->
            <xsl:value-of select="format-number(shop_item/price, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of select="shop_item/currency" disable-output-escaping="yes"/>
         </td>
         <td>
            <!-- Сумма -->
            <xsl:value-of disable-output-escaping="yes" select="format-number(shop_item/price * quantity, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="shop_item/currency"/>
         </td>
         <xsl:if test="count(/shop/shop_warehouse)">
            <td>
               <xsl:choose>
                  <xsl:when test="sum(shop_item/shop_warehouse_item/count) > 0">
                     <select name="warehouse_{shop_item/@id}">
                        <xsl:apply-templates select="shop_item/shop_warehouse_item"/>
                     </select>
                  </xsl:when>
                  <xsl:otherwise>—</xsl:otherwise>
               </xsl:choose>
            </td>
         </xsl:if>
         <td align="center">
            <!-- Отложить -->
            <input type="checkbox" name="postpone_{shop_item/@id}">
               <xsl:if test="postpone = 1">
                  <xsl:attribute name="checked">checked</xsl:attribute>
               </xsl:if>
            </input>
         </td>
      <td align="center"><a class="del" data-id="{shop_item/@id}" href="?delete={shop_item/@id}" title="Удалить товар из корзины" alt="Удалить товар из корзины">Удалить</a></td>
      </tr>
   </xsl:template>


шаблон итоговой строки таблицы заменяем на
   <!-- Итоговая строка таблицы -->
   <xsl:template name="tableFooter">
      <xsl:param name="nodes"/>
      
      <tr class="total">
         <td>Итого:</td>
         <td id="quantity"><xsl:value-of disable-output-escaping="yes" select="sum($nodes/quantity)"/></td>
      <td><xsl:text> </xsl:text></td>
         <td id="itogo">
            <xsl:variable name="subTotals">
               <xsl:for-each select="$nodes">
                  <sum><xsl:value-of select="shop_item/price * quantity"/></sum>
               </xsl:for-each>
            </xsl:variable>
            
            <xsl:value-of select="format-number(sum(exsl:node-set($subTotals)/sum), '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="/shop/shop_currency/name"/>
         </td>
         <xsl:if test="count(/shop/shop_warehouse)">
         <td><xsl:text> </xsl:text></td>
         </xsl:if>
      <td><xsl:text> </xsl:text></td>
      <td><xsl:text> </xsl:text></td>
      </tr>
      <script>
         $().ready(function(e) {
         $('.del').live('click',function(){
         if ( confirm('Вы уверены, что хотите удалить?') ) {
         var tovar = $(this).attr('data-id');
         <xsl:text disable-output-escaping="yes">
            $.get('.','ajax=ajax&amp;delete='+tovar,function(data){
            $('tr#item_'+tovar).remove();
            $('#itogo').html(accounting.formatNumber(data.sum, 2, " ", ",") + ' ' + data.currency );
            $('#quantity').html(data.quantity);
            $('#little_cart').html(data.little_cart);
            },'json');
         </xsl:text>
         }
         return false;
         });
         });
      </script>
   </xsl:template>

Открыть настройки ТДС "Интернет-магазин корзина"

Найти

// Удаляение товара из корзины
if (Core_Array::getGet('delete'))
{
   $shop_item_id = intval(Core_Array::getGet('delete'));

   if ($shop_item_id)
   {
      $oShop_Cart_Controller = Shop_Cart_Controller::instance();
      $oShop_Cart_Controller
         ->shop_item_id($shop_item_id)
         ->delete();
   }
}

заменить на

// Удаляение товара из корзины
if (Core_Array::getGet('delete'))
{
   $shop_item_id = intval(Core_Array::getGet('delete'));

   if ($shop_item_id)
   {
      $oShop_Cart_Controller = Shop_Cart_Controller::instance();
      $oShop_Cart_Controller
         ->shop_item_id($shop_item_id)
         ->delete();
   }
   // если в параметре было указано ajax, необходимо произвести пересчет корзины
   if (Core_Array::getGet('ajax')) {
      
      $aCart = $oShop_Cart_Controller->getAll($oShop);
      $price = 0;
      $quantity = 0;
      foreach ($aCart as $oShop_Cart) {
         $shop_item_id = $oShop_Cart->shop_item_id;
         $oShop_Item_Model = Core_Entity::factory('Shop_Item',$shop_item_id);
         $oShop_Item_Controller = new Shop_Item_Controller();
         $aitemPrice = $oShop_Item_Controller->getPrices($oShop_Item_Model);
         $price += $aitemPrice['price_discount'] * $oShop_Cart->quantity;
         $quantity += $oShop_Cart->quantity;
      }

      ob_start();
      // Краткая корзина
      $Shop_Cart_Controller_Show = new Shop_Cart_Controller_Show(
         $oShop
      );
      $Shop_Cart_Controller_Show
         ->xsl(
            Core_Entity::factory('Xsl')->getByName(
               Core_Array::get(Core_Page::instance()->libParams, 'littleCartXsl')
            )
         )
         ->couponText(Core_Array::get($_SESSION, 'coupon_text'))
         ->show();
      
      $little_cart = ob_get_clean();
      $array = array( 'sum' => $price, 'currency'=> $oShop->shop_currency->name, 'quantity' => $quantity,'little_cart' => $little_cart );
      echo json_encode($array);
      exit();
   }
}


Почти готовое решение, осталось оформить код отвечающий за динамический вывод пустой корзины, после удаления всех товаров
HostDev.pw - модули для HostCMS, Telegram: @hostdev
Авторизация