<?php

defined('HOSTCMS') || exit('HostCMS: access denied.');

/**
 * Online shop.
 *
 * @package HostCMS
 * @subpackage Shop
 * @version 7.x
 * @copyright © 2005-2025, https://www.hostcms.ru
 */
class Shop_Price_Setting_Item_Controller_Delete extends Admin_Form_Action_Controller
{
	/**
	 * Executes the business logic.
	 * @param mixed $operation Operation name
	 */
	public function execute($operation = NULL)
	{
		$shop_price_setting_id = Core_Array::getGet('shop_price_setting_id', 0, 'int');
		$shop_item_id = Core_Array::getGet('shop_item_id', 0, 'int');

		if ($shop_price_setting_id && $shop_item_id)
		{
			$oShop_Price_Setting_Items = Core_Entity::factory('Shop_Price_Setting_Item');
			$oShop_Price_Setting_Items->queryBuilder()
				->where('shop_price_setting_items.shop_price_setting_id', '=', $shop_price_setting_id)
				->where('shop_price_setting_items.shop_item_id', '=', $shop_item_id)
				->limit(1);

			$aShop_Price_Setting_Items = $oShop_Price_Setting_Items->findAll(FALSE);

			if (isset($aShop_Price_Setting_Items[0]))
			{
				$aShop_Price_Setting_Items[0]->delete();
			}

			$windowId = $this->_Admin_Form_Controller->getWindowId();

			$this->_Admin_Form_Controller->addMessage(
				"<script>$('#{$windowId} .shop-item-table tr#shop-item-{$shop_item_id}').remove();</script>"
			);
		}

		return TRUE;
	}
}