<?php

require realpath(__DIR__ . '/../../../../') . "/vars.inc.php";
require_once $INCLUDE_FOLDER . 'index.php';

$nc_core = nc_core::get_object();
$input = $nc_core->input;

$cart = (array) $input->fetch_post('cart');
$cart_params = $input->fetch_post('cart_params');
$item_params = $input->fetch_post('item_params');

$netshop = nc_netshop::get_instance(1);
$dashamail = new DashaMail();

$items = $input->fetch_post('items');

if (is_array($items)) {
  $qty = (int) $input->fetch_post('qty');

  foreach ($items as $item) {
    list($component_id, $item_id) = explode(':', $item);
    $cart[(int) $component_id][(int) $item_id] = $qty;
  }
}

$replace_existing = $input->fetch_post('cart_mode') !== 'add';

foreach ($cart as $component_id => $items) {
  foreach ((array) $items as $item_id => $qty) {

    // Добавлено событие отправки
    if ($qty > 0) {
      $result = $nc_core->event->execute(DashaMail::EVENT_PRODUCT_ADD_TO_CART, $AUTH_USER_ID);
    }else {
      $nc_core->event->execute(DashaMail::EVENT_PRODUCT_REMOVE_TO_CART, $AUTH_USER_ID);
    }

  }
}

// Выполнить стандартные действия с корзиной
require_once '../../netshop/actions/cart.php';

