Advertisement
mr_therabbit

Untitled

Jul 5th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.75 KB | None | 0 0
  1. <?
  2.  
  3. use Bitrix\Main\Loader,
  4.     Bitrix\Main\Localization\Loc,
  5.     Bitrix\Sale;
  6.  
  7. if (!Loader::includeModule('catalog') || !Loader::includeModule('sale')) return;
  8.  
  9. require_once $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/sale/general/sale_act.php';
  10.  
  11. class CSaleActionCondCtrlBasketProps extends CSaleActionCtrlComplex
  12. {
  13.     public static function GetClassName()
  14.     {
  15.         return __CLASS__;
  16.     }
  17.  
  18.     public static function GetControlShow($arParams)
  19.     {
  20.         $arControls = static::GetControls();
  21.         $arResult = array(
  22.             'controlgroup' => true,
  23.             'group' =>  false,
  24.             'label' => 'Свойства товаров в корзине',
  25.             'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
  26.             'children' => array()
  27.         );
  28.         foreach ($arControls as &$arOneControl)
  29.         {
  30.             $arOne = array(
  31.                 'controlId' => $arOneControl['ID'],
  32.                 'group' => ('Y' == $arOneControl['GROUP']),
  33.                 'label' => $arOneControl['LABEL'],
  34.                 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
  35.                 'control' => array(
  36.                     array(
  37.                         'id' => 'prefix',
  38.                         'type' => 'prefix',
  39.                         'text' => $arOneControl['PREFIX']
  40.                     ),
  41.                     static::GetLogicAtom($arOneControl['LOGIC']),
  42.                     static::GetValueAtom($arOneControl['JS_VALUE'])
  43.                 )
  44.             );
  45.             if ('CondBsktPropDiscountSave' == $arOneControl['ID'])
  46.             {
  47.                 $arOne['control'][] = '%';
  48.             }
  49.             if (!empty($arOne))
  50.                 $arResult['children'][] = $arOne;
  51.         }
  52.         if (isset($arOneControl))
  53.             unset($arOneControl);
  54.  
  55.         return $arResult;
  56.     }
  57.  
  58.     public static function GetControls($strControlID = false)
  59.     {
  60.         $arControlList = array(
  61.             'CondBsktPropDiscountSave' => array(
  62.                 'ID' => 'CondBsktPropDiscountSave',
  63.                 'FIELD' => 'DISCOUNT_SAVE',
  64.                 'FIELD_TYPE' => 'double',
  65.                 'LABEL' => 'Процент накопительной скидки',
  66.                 'PREFIX' => 'поле Процент накопительной скидки',
  67.                 'LOGIC' => static::GetLogic(
  68.                     array(
  69.                         BT_COND_LOGIC_EQ,
  70.                         BT_COND_LOGIC_NOT_EQ,
  71.                         BT_COND_LOGIC_GR,
  72.                         BT_COND_LOGIC_LS,
  73.                         BT_COND_LOGIC_EGR,
  74.                         BT_COND_LOGIC_ELS
  75.                     )
  76.                 ),
  77.                 'JS_VALUE' => array(
  78.                     'type' => 'input'
  79.                 ),
  80.             )
  81.         );
  82.  
  83.         foreach ($arControlList as &$control)
  84.         {
  85.             $control['MODULE_ID'] = 'sale';
  86.             $control['MODULE_ENTITY'] = 'sale';
  87.             $control['ENTITY'] = 'PRORS';
  88.             $control['MULTIPLE'] = 'N';
  89.             $control['GROUP'] = 'N';
  90.         }
  91.         unset($control);
  92.  
  93.         if (false === $strControlID)
  94.         {
  95.             return $arControlList;
  96.         }
  97.         elseif (isset($arControlList[$strControlID]))
  98.         {
  99.             return $arControlList[$strControlID];
  100.         }
  101.         else
  102.         {
  103.             return false;
  104.         }
  105.     }
  106.  
  107.     public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
  108.     {
  109.         $strResult = '';
  110.         if (is_string($arControl))
  111.         {
  112.             $arControl = static::GetControls($arControl);
  113.         }
  114.  
  115.         if (count($arControl)) {
  116.             //$strPrefix = 'Site\HelpersShop::searchProps($row, #FIELD#) !== false && ';
  117.             $strPrefix = '';
  118.             foreach ($arControl['LOGIC'] as &$arC) {
  119.                 if ($arC['ID'] == BT_COND_LOGIC_EQ) {
  120.                     if (isset($arC['OP']['N'])) {
  121.                         $arC['OP']['N'] = $strPrefix.'Site\HelpersShop::getDiscountSave($row) == #VALUE#';
  122.                     }//\\ if
  123.                     if (isset($arC['OP']['Y'])) {
  124.                         $arC['OP']['Y'] = $strPrefix.'in_array(#VALUE#, Site\HelpersShop::getDiscountSave($row))';
  125.                     }//\\ if
  126.                 } elseif ($arC['ID'] == BT_COND_LOGIC_NOT_EQ) {
  127.                     if (isset($arC['OP']['N'])) {
  128.                         $arC['OP']['N'] = $strPrefix.'Site\HelpersShop::getDiscountSave($row) != #VALUE#';
  129.                     }//\\ if
  130.                     if (isset($arC['OP']['Y'])) {
  131.                         $arC['OP']['Y'] = $strPrefix.'!in_array(#VALUE#, Site\HelpersShop::getDiscountSave($row))';
  132.                     }//\\ if
  133.                 } elseif ($arC['ID'] == BT_COND_LOGIC_GR) {
  134.                     if (isset($arC['OP']['N'])) {
  135.                         $arC['OP']['N'] = $strPrefix.'Site\HelpersShop::getDiscountSave($row) > #VALUE#';
  136.                     }//\\ if
  137.                     if (isset($arC['OP']['Y'])) {
  138.                         $arC['OP']['Y'] = $strPrefix.'CGlobalCondCtrl::LogicGreat(Site\HelpersShop::getDiscountSave($row), #VALUE#)';
  139.                     }//\\ if
  140.                 } elseif ($arC['ID'] == BT_COND_LOGIC_LS) {
  141.                     if (isset($arC['OP']['N'])) {
  142.                         $arC['OP']['N'] = $strPrefix.'Site\HelpersShop::getDiscountSave($row) < #VALUE#';
  143.                     }//\\ if
  144.                     if (isset($arC['OP']['Y'])) {
  145.                         $arC['OP']['Y'] = $strPrefix.'CGlobalCondCtrl::LogicLess(Site\HelpersShop::getDiscountSave($row), #VALUE#)';
  146.                     }//\\ if
  147.                 } elseif ($arC['ID'] == BT_COND_LOGIC_EGR) {
  148.                     if (isset($arC['OP']['N'])) {
  149.                         $arC['OP']['N'] = $strPrefix.'Site\HelpersShop::getDiscountSave($row) >= #VALUE#';
  150.                     }//\\ if
  151.                     if (isset($arC['OP']['Y'])) {
  152.                         $arC['OP']['Y'] = $strPrefix.'CGlobalCondCtrl::LogicEqualGreat(Site\HelpersShop::getDiscountSave($row), #VALUE#)';
  153.                     }//\\ if
  154.                 } elseif ($arC['ID'] == BT_COND_LOGIC_ELS) {
  155.                     if (isset($arC['OP']['N'])) {
  156.                         $arC['OP']['N'] = $strPrefix.'Site\HelpersShop::getDiscountSave($row) <= #VALUE#';
  157.                     }//\\ if
  158.                     if (isset($arC['OP']['Y'])) {
  159.                         $arC['OP']['Y'] = $strPrefix.'CGlobalCondCtrl::LogicEqualLess(Site\HelpersShop::getDiscountSave($row), #VALUE#)';
  160.                     }//\\ if
  161.                 }//\\ if
  162.             }
  163.         }
  164.  
  165.         $boolError = !is_array($arControl);
  166.  
  167.         if (!$boolError)
  168.         {
  169.             $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
  170.             $boolError = (false === $arValues);
  171.         }
  172.  
  173.         if (!$boolError)
  174.         {
  175.             $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
  176.             if (!isset($arLogic['OP'][$arControl['MULTIPLE']]) || empty($arLogic['OP'][$arControl['MULTIPLE']]))
  177.             {
  178.                 $boolError = true;
  179.             }
  180.             else
  181.             {
  182.                 $valueField = '\''.$arControl['FIELD'].'\'';
  183. // (isset($row['PROPS']) && count($row['PROPS']) && Site\HelpersShop::searchProps($row, 'DISCOUNT_SAVE') !== false && $row['PROPS'][Site\HelpersShop::searchProps($row, 'DISCOUNT_SAVE')]['VALUE'] == 2)
  184.                 switch ($arControl['FIELD_TYPE'])
  185.                 {
  186.                     case 'int':
  187.                     case 'double':
  188.                         $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($valueField, $arValues['value']), $arLogic['OP'][$arControl['MULTIPLE']]);
  189.                         break;
  190.                     case 'char':
  191.                     case 'string':
  192.                     case 'text':
  193.                         $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($valueField, '"'.EscapePHPString($arValues['value']).'"'), $arLogic['OP'][$arControl['MULTIPLE']]);
  194.                         break;
  195.                     case 'date':
  196.                     case 'datetime':
  197.                         $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($valueField, $arValues['value']), $arLogic['OP'][$arControl['MULTIPLE']]);
  198.                         break;
  199.                 }
  200.                 //$strResult = 'isset($row[\'PROPS\']) && count($row[\'PROPS\']) && '.$strResult;
  201.             }
  202.         }
  203.  
  204.         return (!$boolError ? $strResult : false);
  205.     }
  206.  
  207.  
  208.     public static function GetShowIn($arControls)
  209.     {
  210.         $arControls = array(CSaleActionCtrlBasketGroup::GetControlID(), CSaleActionCtrlSubGroup::GetControlID());
  211.         return $arControls;
  212.     }
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement