Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JamesBondsky/bc1238ccef8415c859a2864adf1cb111 to your computer and use it in GitHub Desktop.
Save JamesBondsky/bc1238ccef8415c859a2864adf1cb111 to your computer and use it in GitHub Desktop.
Ограничение службы доставки по свойству товаров в корзине
<?php
class RestrictByOutlet extends Bitrix\Sale\Delivery\Restrictions\Base
{
public static function getClassTitle()
{
return 'Ограничение по свойству outlet';
}
public static function getClassDescription()
{
return 'Ограничение на службы доставки. Если у всех товаров в корзине свойство равно 128, то не показываем эту службу доставки';
}
protected static function extractParams(Bitrix\Sale\Shipment $shipment)
{
$items = [];
foreach ($shipment->getShipmentItemCollection() as $shipmentItem) {
$basketItem = $shipmentItem->getBasketItem();
$items[] = $basketItem->getProductId();
}
return self::getItemsProperty($items);
}
protected static function getItemsProperty($items) {
if (!empty($items)) {
$dbProps = \CIBlockElement::GetList(
[],
[
"ACTIVE" => "Y",
"IBLOCK_ID" => OFFERS_IBLOCK_ID,
"ID" => array_values($items),
"!PROPERTY_OF_SEASON" => 128,
],
false,
false,
[
'IBLOCK_ID',
'ID',
'NAME',
'PROPERTY_OUTLET',
]
);
$itemsFilter = [];
while($ob = $dbProps->Fetch())
{
$itemsFilter[] = $ob;
}
return $itemsFilter;
}
return array();
}
public static function getParamsStructure($deliveryId = 0)
{
return array();
}
public static function check($shipmentParams, array $restrictionParams, $deliveryId = 0)
{
if (!empty($shipmentParams)) return true;
else return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment