Код для ТДС корзины

// Добавление товара в корзину if (Core_Array::getRequest('add')) { // Запрещаем индексацию страницы корзины Core_Page::instance()->response->header('X-Robots-Tag', 'none'); $add = Core_Array::getRequest('add'); !is_array($add) && ($add = [$add]); $count = Core_Array::getRequest('count', 1); !is_array($count) && ($count = [$count]); $oShop_Cart_Controller = Shop_Cart_Controller::instance(); foreach ($add as $key => $shop_item_id) { $options = Core_Array::getRequest('option_' . $shop_item_id, []); !is_array($options) && ($options = [$options]); $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($options)); $options = iterator_to_array($iterator, false); sort($options); $oShop_Cart_Controller ->clear() ->checkStock($bCheckStock) ->options($options) ->shop_item_id(intval($shop_item_id)) ->quantity(intval(Core_Array::get($count, $key, 1))) ->add(); } } if (Core_Array::getRequest('_', false) && Core_Array::getRequest('changeOption')) { $shop_item_id = intval(Core_Array::getGet('changeOption')); $aResult = []; ob_start(); if ($shop_item_id) { HostDev_Shop_Option_Controller::CartChangeOption($shop_item_id, $bCheckStock); } $changeoption = ob_get_clean(); ob_start(); // Краткая корзина $Little_Cart_Controller_Show = new Shop_Cart_Controller_Show($oShop); $Little_Cart_Controller_Show ->xsl(Core_Entity::factory('Xsl')->getByName(Core_Array::get(Core_Page::instance()->libParams, 'littleCartXsl'))) ->couponText(Core_Str::stripTags(Core_Array::get(Core_Array::get($_SESSION, 'hostcmsOrder', []), 'coupon_text'))) ->show(); $aResult['little'] = ob_get_clean(); 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, 'cartXsl'))) ->addEntity(Core::factory('Core_Xml_Entity')->name('change_option')->value($changeoption)) ->couponText(Core_Str::stripTags(Core_Array::get(Core_Array::get($_SESSION, 'hostcmsOrder', []), 'coupon_text'))) ->show(); $aResult['cart'] = ob_get_clean(); echo json_encode($aResult); exit(); } // Ajax if (Core_Array::getRequest('_', false) && (Core_Array::getRequest('add') || Core_Array::getRequest('loadCart'))) { 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_Str::stripTags(Core_Array::get(Core_Array::get($_SESSION, 'hostcmsOrder', []), 'coupon_text'))) ->show(); echo json_encode(ob_get_clean()); exit(); } // Удаляение товара из корзины if (Core_Array::getGet('delete')) { $shop_item_id = intval(Core_Array::getGet('delete')); if ($shop_item_id) { $options = Core_Array::getRequest('option_' . $shop_item_id, []); !is_array($options) && ($options = [$options]); $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($options)); $options = iterator_to_array($iterator, false); sort($options); $oShop_Cart_Controller = Shop_Cart_Controller::instance(); $oShop_Cart_Controller ->clear() ->options($options) ->shop_item_id($shop_item_id) ->delete(); header('Location:' . Core::$url['path']); die(); } } if (Core_Array::getPost('recount') || Core_Array::getPost('step') == 1) { $oShop_Cart_Controller = Shop_Cart_Controller::instance(); $aCart = $oShop_Cart_Controller->getAll($oShop); // Склад по умолчанию $oShop_Warehouse = $oShop->Shop_Warehouses->getDefault(); foreach ($aCart as $oShop_Cart) { $aOptions = $oShop_Cart->options; if (is_array($aOptions)) { if (sizeof($aOptions)) { $sOptions = '_' . implode('_', $aOptions); } else { $sOptions = ''; } } else { $aOptions = []; $sOptions = ''; } $quantity = Core_Array::getPost('quantity_' . $oShop_Cart->shop_item_id . $sOptions); // Количество было передано if (!is_null($quantity)) { $oShop_Cart_Controller ->clear() ->checkStock($bCheckStock) ->shop_item_id($oShop_Cart->shop_item_id) ->options($aOptions) ->quantity($quantity) ->postpone(is_null(Core_Array::getPost('postpone_' . $oShop_Cart->shop_item_id . $sOptions)) ? 0 : 1) ->shop_warehouse_id(Core_Array::getPost('warehouse_' . $oShop_Cart->shop_item_id . $sOptions, !is_null($oShop_Warehouse) ? $oShop_Warehouse->id : 0)) ->update(); } } }

30.03.2023