# Ограничение по складу

Если Вам нужно ограничить показ каких либо товаров в регионе по привязанному к нему складу,

<div data-full-width="true"><figure><img src="/files/cCzR0JNQco2uf6OLYreQ" alt=""><figcaption></figcaption></figure></div>

то в контроллере показа товаров можно добавить следующее ограничение:

{% code lineNumbers="true" fullWidth="true" %}

```php
// ограничение по мультирегионам MultiRegion
if(isset(Core_Page::instance()->multiregion) && $oMultiRegion = Core_Page::instance()->multiregion)
{
	$aReturn = $oMultiRegion->getWarehouses();

	if(count($aReturn))
	{
		// подключаем склады
		$Shop_Controller_Show->warehouseMode('in-stock');

		// ограничиваем по ID склада в регионе
		$Shop_Controller_Show
			->shopItems()
			//->shopItemsInit() // для модуля "Умные фильтры"
				->queryBuilder()
					->where('shop_warehouse_items.shop_warehouse_id','IN',$aReturn);
	}
}
```

{% endcode %}

Для модификаций - добавьте хук в `bootstrap.php` или в нужную ТДС

{% code lineNumbers="true" fullWidth="true" %}

```php
class My_Multiregion_Observer
{
    static public function onBeforeSelectModifications($object, $args)
    {
        list($oShop_Items_Modifications) = $args;
        
        if(isset(Core_Page::instance()->multiregion) && $oMultiRegion = Core_Page::instance()->multiregion)
        // огранчиение только для карточки товара
        //if(isset(Core_Page::instance()->item) && Core_Page::instance()->item && isset(Core_Page::instance()->multiregion) && $oMultiRegion = Core_Page::instance()->multiregion)
        {
            $aReturn = $oMultiRegion->getWarehouses();
            
            if(count($aReturn))
            {
    		// подключаем склады
                $oShop_Items_Modifications
                    ->queryBuilder()
        		->join('shop_warehouse_items', 'shop_warehouse_items.shop_item_id', '=', 'shop_items.id')
        		->join('shop_warehouses', 'shop_warehouses.id', '=', 'shop_warehouse_items.shop_warehouse_id')
        		->where('shop_warehouses.active', '=', 1)
        		->where('shop_warehouses.deleted', '=', 0)
        		->having('SUM(shop_warehouse_items.count)', '>', 0)
                        ->groupBy('shop_items.id');
    
    		// ограничиваем по ID склада в регионе
    		$oShop_Items_Modifications
                    ->queryBuilder()
                        ->where('shop_warehouse_items.shop_warehouse_id','IN',$aReturn);
            }
        }
    }
}

Core_Event::attach('shop_item.onBeforeSelectModifications', array('My_Multiregion_Observer', 'onBeforeSelectModifications'));
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.morozovpimnev.ru/multiregion/ogranichenie-po-skladu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
