Guest User

OnGetOptimalPrice handler

a guest
Apr 24th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. AddEventHandler("catalog", "OnGetOptimalPrice", 'OnGetOptimalPriceHandler');
  2.  
  3. function OnGetOptimalPriceHandler($productID,$quantity){
  4.  
  5.  
  6. if ( CModule::IncludeModule("catalog") && CModule::IncludeModule("iblock") ){
  7.  
  8. $ar_res = CCatalogProduct::GetByID($productID);
  9.  
  10.  
  11. if ( $quantity > 0 ){
  12.  
  13. $priceId = "1";
  14. $keyPrice = "CATALOG_PRICE_1";
  15. $code = "BASE";
  16.  
  17. }else{
  18. $priceId = "2";
  19. $keyPrice = "CATALOG_PRICE_2";
  20. $code = "PREDZAKAZ_PRICE";
  21. }
  22.  
  23. #$discount_arr = CCatalogDiscount::GetByID($productID);
  24.  
  25.  
  26. $obj_el = CIBlockElement::GetList( array(),
  27. array("ID"=>$productID,"IBLOCK_ID"=>"2"),
  28. false,
  29. false,
  30. array("ID","IBLOCK_ID","CATALOG_GROUP_".$priceId)
  31. );
  32.  
  33.  
  34. if ( $element = $obj_el->GetNext()){
  35.  
  36. #echo "<pre>"; print_r ($ar_res); echo "</pre>";
  37.  
  38.  
  39. return array(
  40. 'PRICE' => array(
  41. 'ID' => $priceId,
  42. 'CATALOG_GROUP_ID' => $code,
  43. 'PRICE' => $element[$keyPrice],
  44. 'CURRENCY' => "RUB",
  45. 'ELEMENT_IBLOCK_ID' => $element["ID"],
  46. 'VAT_RATE' => $ar_res["VAT_ID"],
  47. 'VAT_INCLUDED' => $ar_res["VAT_INCLUDED"]
  48. ),
  49. 'DISCOUNT_PRICE' => '12208',
  50. 'DISCOUNT'=>array(
  51. 'VALUE'=> '5',
  52. 'VALUE_TYPE'=>'P',
  53. 'ID' => '2',
  54. 'CURRENCY'=>'RUB',
  55. 'SITE_ID'=>SITE_ID,
  56. 'ACTIVE'=>'Y',
  57. 'RENEWAL'=>'N',
  58. 'ACTIVE_FROM' => '',
  59. 'ACTIVE_TO' => '',
  60. 'MAX_DISCOUNT' =>'0',
  61. 'COUPON' => '',
  62. 'COUPON_ONE_TIME' => '',
  63. 'COUPON_ACTIVE' => '',
  64. "SORT"=>"500"
  65.  
  66.  
  67.  
  68. )
  69. );
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. }
  79.  
  80.  
  81. }
Add Comment
Please, Sign In to add comment