feat: integrate yandex metrika ecommerce
This commit is contained in:
@@ -7,6 +7,7 @@ use Cart\Currency;
|
||||
use Config;
|
||||
use Language;
|
||||
use Loader;
|
||||
use ModelCatalogCategory;
|
||||
use ModelCatalogProduct;
|
||||
use ModelDesignBanner;
|
||||
use ModelSettingSetting;
|
||||
@@ -27,6 +28,7 @@ use Url;
|
||||
* @property ModelCatalogProduct $model_catalog_product
|
||||
* @property ModelSettingSetting $model_setting_setting
|
||||
* @property ModelDesignBanner $model_design_banner
|
||||
* @property ModelCatalogCategory $model_catalog_category
|
||||
*/
|
||||
class OcRegistryDecorator
|
||||
{
|
||||
|
||||
@@ -55,7 +55,7 @@ class ProductsHandler
|
||||
], Response::HTTP_NOT_FOUND);
|
||||
} catch (Exception $exception) {
|
||||
$this->logger->logException($exception);
|
||||
throw new RuntimeException('Error get product with id ' . $productId, 500, $exception);
|
||||
throw new RuntimeException('Error get product with id ' . $productId, 500);
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
|
||||
@@ -56,6 +56,7 @@ class SettingsHandler
|
||||
'store_enabled' => $this->settings->get('store_enabled'),
|
||||
'feature_coupons' => $this->settings->get('feature_coupons') ?? false,
|
||||
'feature_vouchers' => $this->settings->get('feature_vouchers') ?? false,
|
||||
'currency_code' => $this->settings->get('oc_default_currency', 'RUB'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +195,7 @@ class OrderCreateService
|
||||
'total' => $orderData['total'],
|
||||
'final_total_numeric' => $orderData['total_numeric'],
|
||||
'currency' => $currencyCode,
|
||||
'products' => $products,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use Openguru\OpenCartFramework\OpenCart\Decorators\OcRegistryDecorator;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\Builder;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\JoinClause;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\RawExpression;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\Table;
|
||||
use Openguru\OpenCartFramework\Support\Arr;
|
||||
use Openguru\OpenCartFramework\Support\PaginationHelper;
|
||||
|
||||
@@ -61,6 +62,8 @@ class ProductsService
|
||||
$filters = $params['filters'] ?? [];
|
||||
|
||||
$customerGroupId = (int) $this->settings->get('oc_customer_group_id');
|
||||
$currency = $this->settings->get('oc_default_currency');
|
||||
|
||||
$specialPriceSql = "(SELECT price
|
||||
FROM oc_product_special ps
|
||||
WHERE ps.product_id = products.product_id
|
||||
@@ -78,6 +81,8 @@ class ProductsService
|
||||
'products.price' => 'price',
|
||||
'products.image' => 'product_image',
|
||||
'products.tax_class_id' => 'tax_class_id',
|
||||
'manufacturer.name' => 'manufacturer_name',
|
||||
'category_description.name' => 'category_name',
|
||||
new RawExpression($specialPriceSql),
|
||||
])
|
||||
->from(db_table('product'), 'products')
|
||||
@@ -88,6 +93,20 @@ class ProductsService
|
||||
->where('product_description.language_id', '=', $languageId);
|
||||
}
|
||||
)
|
||||
->leftJoin(new Table(db_table('manufacturer'), 'manufacturer'), function (JoinClause $join) {
|
||||
$join->on('products.manufacturer_id', '=', 'manufacturer.manufacturer_id');
|
||||
})
|
||||
->leftJoin(new Table(db_table('product_to_category'), 'product_to_category'), function (JoinClause $join) {
|
||||
$join->on('products.product_id', '=', 'product_to_category.product_id')
|
||||
->where('product_to_category.main_category', '=', 1);
|
||||
})
|
||||
->leftJoin(
|
||||
new Table(db_table('category_description'), 'category_description'),
|
||||
function (JoinClause $join) use ($languageId) {
|
||||
$join->on('product_to_category.category_id', '=', 'category_description.category_id')
|
||||
->where('category_description.language_id', '=', $languageId);
|
||||
}
|
||||
)
|
||||
->where('products.status', '=', 1)
|
||||
->whereRaw('products.date_available < NOW()')
|
||||
->when($search, function (Builder $query) use ($search) {
|
||||
@@ -136,7 +155,7 @@ class ProductsService
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => array_map(function ($product) use ($productsImagesMap, $imageWidth, $imageHeight) {
|
||||
'data' => array_map(function ($product) use ($productsImagesMap, $imageWidth, $imageHeight, $currency) {
|
||||
$allImages = [];
|
||||
|
||||
$image = $this->ocImageTool->resize(
|
||||
@@ -151,24 +170,24 @@ class ProductsService
|
||||
'alt' => Utils::htmlEntityEncode($product['product_name']),
|
||||
];
|
||||
|
||||
$price = $this->currency->format(
|
||||
$this->tax->calculate(
|
||||
$product['price'],
|
||||
$product['tax_class_id'],
|
||||
$this->settings->get('oc_config_tax'),
|
||||
),
|
||||
$this->settings->get('oc_default_currency'),
|
||||
$priceNumeric = $this->tax->calculate(
|
||||
$product['price'],
|
||||
$product['tax_class_id'],
|
||||
$this->settings->get('oc_config_tax'),
|
||||
);
|
||||
$price = $this->currency->format($priceNumeric, $currency);
|
||||
|
||||
$special = false;
|
||||
$specialPriceNumeric = null;
|
||||
if ($product['special'] && (float) $product['special'] >= 0) {
|
||||
$specialPriceNumeric = $this->tax->calculate(
|
||||
$product['special'],
|
||||
$product['tax_class_id'],
|
||||
$this->settings->get('oc_config_tax'),
|
||||
);
|
||||
$special = $this->currency->format(
|
||||
$this->tax->calculate(
|
||||
$product['special'],
|
||||
$product['tax_class_id'],
|
||||
$this->settings->get('oc_config_tax'),
|
||||
),
|
||||
$this->settings->get('oc_default_currency'),
|
||||
$specialPriceNumeric,
|
||||
$currency,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -183,6 +202,11 @@ class ProductsService
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'images' => $allImages,
|
||||
'special_numeric' => $specialPriceNumeric,
|
||||
'price_numeric' => $priceNumeric,
|
||||
'final_price_numeric' => $specialPriceNumeric ?: $priceNumeric,
|
||||
'manufacturer_name' => $product['manufacturer_name'],
|
||||
'category_name' => $product['category_name'],
|
||||
];
|
||||
}, $products),
|
||||
|
||||
@@ -400,8 +424,27 @@ class ProductsService
|
||||
|
||||
$data['recurrings'] = $this->oc->model_catalog_product->getProfiles($productId);
|
||||
|
||||
$data['category'] = $this->getProductMainCategory($productId);
|
||||
$data['id'] = $productId;
|
||||
|
||||
$this->oc->model_catalog_product->updateViewed($productId);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getProductMainCategory(int $productId): ?array
|
||||
{
|
||||
return $this->queryBuilder->newQuery()
|
||||
->select([
|
||||
'category_description.category_id' => 'id',
|
||||
'category_description.name' => 'name',
|
||||
])
|
||||
->from(db_table('category_description'), 'category_description')
|
||||
->join(new Table(db_table('product_to_category'), 'product_to_category'), function (JoinClause $join) {
|
||||
$join->on('product_to_category.category_id', '=', 'category_description.category_id')
|
||||
->where('product_to_category.main_category', '=', 1);
|
||||
})
|
||||
->where('product_to_category.product_id', '=', $productId)
|
||||
->firstOrNull();
|
||||
}
|
||||
}
|
||||
0
module/oc_telegram_shop/upload/oc_telegram_shop/src/Support/Utils.php
Normal file → Executable file
0
module/oc_telegram_shop/upload/oc_telegram_shop/src/Support/Utils.php
Normal file → Executable file
0
module/oc_telegram_shop/upload/oc_telegram_shop/tests/Unit/RequestTest.php
Normal file → Executable file
0
module/oc_telegram_shop/upload/oc_telegram_shop/tests/Unit/RequestTest.php
Normal file → Executable file
Reference in New Issue
Block a user