1. В папке /core/components/minishop2/custom/cart/ создаете файл mascarthandlerstatus.class.php который будет расширять класс корзины
2. В этом файле пишете
==============================================
<?php
if(!class_exists('msCartInterface')) {
require_once dirname(dirname(dirname(__FILE__))) . '/model/minishop2/mscarthandler.class.php';
}
class msCartHandlerStatus extends msCartHandler implements msCartInterface{
public function status($data = array())
{
$status = array(
'total_count' => 0,
'total_count_position' => 0,
'total_cost' => 0,
'total_weight' => 0
);
foreach ($this->cart as $item) {
if (empty($item['ctx']) || $item['ctx'] == $this->ctx) {
$status['total_count_position'] += 1;
$status['total_count'] += $item['count'];
$status['total_cost'] += $item['price'] * $item['count'];
$status['total_weight'] += $item['weight'] * $item['count'];
}
}
return array_merge($data, $status);
}
}
==============================================
3. В плагине Console (если его нет, то надо поставить) выполняем следующий код==============================================
if ($miniShop2 = $modx->getService('miniShop2')) {
$miniShop2->addService('cart', 'msCartHandlerStatus',
'{core_path}components/minishop2/custom/cart/mascarthandlerstatus.class.php'
);
}==============================================
Таким образом мы добавляем новый обработчик корзины4. Далее идем в Системные настройки -> mimishop2 -> Класс обработчик корзины и указываем там msCartHandlerStatus
5. Теперь в плейсхолдере total_count_position будет отображаться количество позиций в корзине
6. Что бы все это и по аяксу обновлялось, в js в ваших скриптах или просто в конце страницы (главное что бы он был после подключения скрипта от минишопа) добавляем такой код
==============================================
miniShop2.Cart.status = function (status) {
if (status['total_count'] < 1) {
location.reload();
}
else {
var $miniCart = $(miniShop2.Cart.miniCart);
if (status['total_count'] > 0 && !$miniCart.hasClass(miniShop2.Cart.miniCartNotEmptyClass)) {
$miniCart.addClass(miniShop2.Cart.miniCartNotEmptyClass);
}
$(miniShop2.Cart.totalWeight).text(miniShop2.Utils.formatWeight(status['total_weight']));
$(miniShop2.Cart.totalCount).text(status['total_count']);
$(miniShop2.Cart.totalCost).text(miniShop2.Utils.formatPrice(status['total_cost']));
$('.ms2_total_count_position').text(status['total_count_position']);
if ($(miniShop2.Order.orderCost, miniShop2.Order.order).length) {
miniShop2.Order.getcost();
}
}
};
==============================================
7. Теперь в миникорзине или корзине можно писать так<span class="ms2_total_count_position">{$total_count_position}</span>
Комментариев нет:
Отправить комментарий