Added filter example to doc

This commit is contained in:
gleemand 2022-09-07 13:19:52 +03:00 committed by GitHub
parent 960ed4438a
commit 1861b5255a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,63 +1,28 @@
# Examples # Examples
- [Classes](#classes) - [Classes](#classes)
- [Prices with discounts to icml](#prices-with-discounts-to-icml) - [Example](#example)
- [Filters](#filters) - [Filters](#filters)
- [Set order custom field on status change](#set-order-custom-field-on-status-change) - [Set order custom field on status change](#set-order-custom-field-on-status-change)
- [Prices with discounts to icml](#prices-with-discounts-to-icml)
## Classes ## Classes
### Prices with discounts to ICML ### Example
Customization for generate ICML catalog with prices including discounts
Put code to `.../retailcrm/custom/classes/RetailcrmCatalog.php`:
```php ```php
<...>
$price = !empty($product['rate'])
? round($product['price'], 2) + (round($product['price'], 2) * $product['rate'] / 100)
: round($product['price'], 2);
// CUSTOMIZATION
$id_group = 0; // All groups
$id_country = 0; // All countries
$id_currency = 0; // All currencies
$id_shop = Shop::getContextShopID();
$specificPrice = SpecificPrice::getSpecificPrice($product['id_product'], $id_shop, $id_currency, $id_country, $id_group, null);
if (isset($specificPrice['reduction'])) {
if ($specificPrice['reduction_type'] === 'amount') {
$price = round($price - $specificPrice['reduction'], 2);
} elseif ($specificPrice['reduction_type'] === 'percentage') {
$price = round($price - ($price * $specificPrice['reduction']), 2);
}
}
// END OF CUSTOMIZATION
if (!empty($product['manufacturer_name'])) {
$vendor = $product['manufacturer_name'];
} else {
$vendor = null;
}
<...>
``` ```
## Filters ## Filters
### Set order custom field on status change ### Set order custom field on status change
Put code to `custom/filters/RetailcrmFilterOrderStatusUpdate.php`:
```php ```php
<?php <?php
// custom/filters/RetailcrmFilterOrderStatusUpdate.php // custom/filters/RetailcrmFilterOrderStatusUpdate.php
class RetailcrmFilterOrderStatusUpdate implements RetailcrmFilterInterface class RetailcrmFilterOrderStatusUpdate implements RetailcrmFilterInterface
{ {
/**
* {@inheritDoc}
*/
public static function filter($object, array $parameters) public static function filter($object, array $parameters)
{ {
// get data from Order object // get data from Order object
@ -85,3 +50,35 @@ class RetailcrmFilterOrderStatusUpdate implements RetailcrmFilterInterface
} }
} }
``` ```
### Prices with discounts to ICML
```php
<?php
// custom/filters/RetailcrmFilterProcessOffer.php
class RetailcrmFilterProcessOffer implements RetailcrmFilterInterface
{
public static function filter($object, array $parameters)
{
$product = $parameters['product'];
$price = $object['price'] ?? null;
$id_group = 0; // All groups
$id_country = 0; // All countries
$id_currency = 0; // All currencies
$id_shop = Shop::getContextShopID();
$specificPrice = SpecificPrice::getSpecificPrice($product['id_product'], $id_shop, $id_currency, $id_country, $id_group, null);
if (isset($specificPrice['reduction'])) {
if ($specificPrice['reduction_type'] === 'amount') {
$object['price'] = round($price - $specificPrice['reduction'], 0);
} elseif ($specificPrice['reduction_type'] === 'percentage') {
$object['price'] = round($price - ($price * $specificPrice['reduction']), 0);
}
}
return $object;
}
}
```