Documentation

GetList

Description and parameters

CDBResult
CCatalogDiscountCoupon::GetList (
array $arOrder = array(),
array $arFilter = array(),
mixed $arGroupBy = false,
mixed $arNavStartParams = false,
array $arSelectFields = array()
);

Method selects coupons corresponding to conditions. Non-static method.

Call parameters

Parameter Description
arOrder Array consisting of array(by1=>order1[, by2=>order2 [, ..]]), where by - field for sorting, can have the following values:
  • ID - coupon code (ID);
  • DISCOUNT_ID - discount code (ID);
  • ACTIVE - coupon active status;
  • ONE_TIME - flag for coupon multi use;
  • COUPON - coupon code;
  • DATE_APPLY - date of applied coupon;
field 'order' - sort direction, can have the following values:
  • asc - by ascension;
  • desc - by descension.
Optional. By default, coupons are not sorted.
arFilter Array with parameters to build selection filter. Has the following appearance:
array(
"[modifier1][operator1]field_name1" => "value1",
"[modifier2][operator2]field_name2" => "value2",
. . .
)
Records that satisfy the filter are returned in the result and records that doesn't satisfy filter conditions are not included.
The following modifiers are deemed as permissible:
  • ! - negation;
  • + - null, 0 and empty string also satisfy filter conditions.
The operators are deemed as permissible:
  • >= - field value is higher or equal to the value passed to filter;
  • > - field value is strictly higher then value passed to filter;
  • <= - field value is less or equal to value passed to filter;
  • < - field value is strictly less than value passed to filter;
  • @ - operator can be used for in integer and real data when passing set of values (array). In this case, hen generating SQL query uses the SQL operatorIN, producing record form;
  • ~ - field value is checked for comparison to the template passed to filter;
  • % - field value is checked for comparison to the string passed to filter according to query language.
"field name" can have values:
  • ID - coupon code (ID, integer);
  • DISCOUNT_ID - discount code (ID, integer);
  • ACTIVE - active status filter (Y|N); passing empty value ("ACTIVE"=>"") prints coupons without their status (string);
  • ONE_TIME - flag for single use coupon (Y|N); passing empty value ("ONE_TIME"=>"") prints coupons without their type (string);
  • COUPON - coupon code (mask);
  • DATE_APPLY - date of applied coupon (date);
  • DESCRIPTION - comment (mask);
Filter value - single value or array with values.
Optional. By default, coupons are not filtered.
arGroupBy Array with fields for coupon grouping. Has the appearance:
array("field_name1", "field_names", . . .)
"field_nameN" can have any catalog field.

In case array is empty, method returns number of records satisfying the filter.
Default value - false - indicates that the result won't be grouped.
arNavStartParams Array with selection parameters. Can contain the following keys:
  • "nTopCount" - number of returned records will be limited from top by this key;
  • any key, received by method CDBResult::NavQuery as the third parameter.
Optional. False by default - coupons are not limited.
arSelectedFields Array with record fields to be returned by the method. You can indicate the following fields: ID, DISCOUNT_ID, ACTIVE, ONE_TIME, COUPON, DATE_APPLY, DISCOUNT_NAME and DESCRIPTION.
In case array contains the value "*", returns all available fields.
Optional. By default prints all fields.

Returned value

Method returns CDBResult class object.

See Also

Examples

Example for getting coupon by "Coupon code":

if (CModule::IncludeModule("catalog"))
{ 
   $arFilter = array('COUPON' => 'CP-R8RFW-5YGGPZJ'); 
   $dbCoupon = CCatalogDiscountCoupon::GetList (array(), $arFilter); 
   if($arCoupon = $dbCoupon->Fetch()) 
   { 
       echo "<pre>"; 
       print_r($arCoupon); 
       echo "</pre>"; 
   } 
   else
   { 
       echo "coupon unavailable"; 
   } 
}

© «Bitrix24», 2001-2024