Удалил googleshopping

This commit is contained in:
Konstantin
2026-05-30 09:52:37 +03:00
parent 51109b7a3c
commit 2b8d4dc057
28 changed files with 0 additions and 7173 deletions
@@ -1,380 +0,0 @@
<?php
use \googleshopping\traits\StoreLoader;
use \googleshopping\traits\LibraryLoader;
class ControllerExtensionAdvertiseGoogle extends Controller {
use StoreLoader;
use LibraryLoader;
private $store_id = 0;
public function __construct($registry) {
parent::__construct($registry);
if (getenv("ADVERTISE_GOOGLE_STORE_ID")) {
$this->store_id = (int)getenv("ADVERTISE_GOOGLE_STORE_ID");
} else {
$this->store_id = (int)$this->config->get('config_store_id');
}
$this->loadStore($this->store_id);
}
public function google_global_site_tag(&$route, &$data, &$output) {
// In case the extension is disabled, do nothing
if (!$this->setting->get('advertise_google_status')) {
return;
}
// If there is no tracker, do nothing
if (!$this->setting->has('advertise_google_conversion_tracker')) {
return;
}
$tracker = $this->setting->get('advertise_google_conversion_tracker');
// Insert the tags before the closing <head> tag
$output = str_replace('</head>', $tracker['google_global_site_tag'] . '</head>', $output);
}
public function before_checkout_success(&$route, &$data) {
// In case the extension is disabled, do nothing
if (!$this->setting->get('advertise_google_status')) {
return;
}
// If there is no tracker, do nothing
if (!$this->setting->has('advertise_google_conversion_tracker')) {
return;
}
// In case there is no order, do nothing
if (!isset($this->session->data['order_id'])) {
return;
}
if (!$this->registry->has('googleshopping')) {
$this->loadLibrary($this->store_id);
}
$this->load->model('checkout/order');
$this->load->model('extension/advertise/google');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$tracker = $this->setting->get('advertise_google_conversion_tracker');
$currency = $order_info['currency_code'];
$total = $this->googleshopping->convertAndFormat($order_info['total'], $currency);
$search = array(
'{VALUE}',
'{CURRENCY}'
);
$replace = array(
$total,
$currency
);
$snippet = str_replace($search, $replace, $tracker['google_event_snippet']);
// Store the snippet to display it in the order success view
$tax = 0;
$shipping = 0;
$coupon = $this->model_extension_advertise_google->getCoupon($order_info['order_id']);
foreach ($this->model_checkout_order->getOrderTotals($order_info['order_id']) as $order_total) {
if ($order_total['code'] == 'shipping') {
$shipping += $this->googleshopping->convertAndFormat($order_total['value'], $currency);
}
if ($order_total['code'] == 'tax') {
$tax += $this->googleshopping->convertAndFormat($order_total['value'], $currency);
}
}
$order_products = $this->model_checkout_order->getOrderProducts($order_info['order_id']);
foreach ($order_products as &$order_product) {
$order_product['option'] = $this->model_checkout_order->getOrderOptions($order_info['order_id'], $order_product['order_product_id']);
}
$purchase_data = array(
'transaction_id' => $order_info['order_id'],
'value' => $total,
'currency' => $currency,
'tax' => $tax,
'shipping' => $shipping,
'items' => $this->model_extension_advertise_google->getRemarketingItems($order_products, $order_info['store_id']),
'ecomm_prodid' => $this->model_extension_advertise_google->getRemarketingProductIds($order_products, $order_info['store_id'])
);
if ($coupon !== null) {
$purchase_data['coupon'] = $coupon;
}
$this->googleshopping->setEventSnippet($snippet);
$this->googleshopping->setPurchaseData($purchase_data);
}
public function google_dynamic_remarketing_purchase(&$route, &$data, &$output) {
// In case the extension is disabled, do nothing
if (!$this->setting->get('advertise_google_status')) {
return;
}
// If the library has not been loaded, or if there is no snippet, do nothing
if (!$this->registry->has('googleshopping') || $this->googleshopping->getEventSnippet() === null || $this->googleshopping->getPurchaseData() === null) {
return;
}
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
$purchase_data = $this->googleshopping->getPurchaseData();
$data['transaction_id'] = $purchase_data['transaction_id'];
$data['value'] = $purchase_data['value'];
$data['currency'] = $purchase_data['currency'];
$data['tax'] = $purchase_data['tax'];
$data['shipping'] = $purchase_data['shipping'];
$data['items'] = json_encode($purchase_data['items']);
$data['ecomm_prodid'] = json_encode($purchase_data['ecomm_prodid']);
$data['ecomm_totalvalue'] = $purchase_data['value'];
$purchase_snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_purchase', $data);
// Insert the snippet after the output
$output = str_replace('</body>', $this->googleshopping->getEventSnippet() . $purchase_snippet . '</body>', $output);
}
public function google_dynamic_remarketing_home(&$route, &$data, &$output) {
// In case the extension is disabled, do nothing
if (!$this->setting->get('advertise_google_status')) {
return;
}
// If we are not on the home page, do nothing
if (isset($this->request->get['route']) && $this->request->get['route'] != $this->config->get('action_default')) {
return;
}
if (!$this->registry->has('googleshopping')) {
$this->loadLibrary($this->store_id);
}
if (null === $this->googleshopping->getEventSnippetSendTo()) {
return;
}
$data = array();
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_home', $data);
// Insert the snippet after the output
$output = str_replace('</body>', $snippet . '</body>', $output);
}
public function google_dynamic_remarketing_searchresults(&$route, &$data, &$output) {
// In case the extension is disabled, do nothing
if (!$this->setting->get('advertise_google_status')) {
return;
}
// If we are not on the search page, do nothing
if (!isset($this->request->get['route']) || $this->request->get['route'] != 'product/search' || !isset($this->request->get['search'])) {
return;
}
if (!$this->registry->has('googleshopping')) {
$this->loadLibrary($this->store_id);
}
if (null === $this->googleshopping->getEventSnippetSendTo()) {
return;
}
$data = array();
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
$data['search_term'] = $this->request->get['search'];
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_searchresults', $data);
// Insert the snippet after the output
$output = str_replace('</body>', $snippet . '</body>', $output);
}
public function google_dynamic_remarketing_category(&$route, &$data, &$output) {
// In case the extension is disabled, do nothing
if (!$this->setting->get('advertise_google_status')) {
return;
}
// If we are not on the search page, do nothing
if (!isset($this->request->get['route']) || $this->request->get['route'] != 'product/category') {
return;
}
if (!$this->registry->has('googleshopping')) {
$this->loadLibrary($this->store_id);
}
if (null === $this->googleshopping->getEventSnippetSendTo()) {
return;
}
if (isset($this->request->get['path'])) {
$parts = explode('_', $this->request->get['path']);
$category_id = (int)end($parts);
} else if (isset($this->request->get['category_id'])) {
$category_id = (int)$this->request->get['category_id'];
} else {
$category_id = 0;
}
$this->load->model('extension/advertise/google');
$data = array();
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
$data['description'] = str_replace('"', '\\"', $this->model_extension_advertise_google->getHumanReadableOpenCartCategory($category_id));
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_category', $data);
// Insert the snippet after the output
$output = str_replace('</body>', $snippet . '</body>', $output);
}
public function google_dynamic_remarketing_product(&$route, &$data, &$output) {
// In case the extension is disabled, do nothing
if (!$this->setting->get('advertise_google_status')) {
return;
}
// If we do not know the viewed product, do nothing
if (!isset($this->request->get['product_id']) || !isset($this->request->get['route']) || $this->request->get['route'] != 'product/product') {
return;
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct((int)$this->request->get['product_id']);
// If product does not exist, do nothing
if (!$product_info) {
return;
}
if (!$this->registry->has('googleshopping')) {
$this->loadLibrary($this->store_id);
}
if (null === $this->googleshopping->getEventSnippetSendTo()) {
return;
}
$this->load->model('extension/advertise/google');
$category_name = $this->model_extension_advertise_google->getHumanReadableCategory($product_info['product_id'], $this->store_id);
$option_map = $this->model_extension_advertise_google->getSizeAndColorOptionMap($product_info['product_id'], $this->store_id);
$data = array();
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
$data['option_map'] = json_encode($option_map);
$data['brand'] = $product_info['manufacturer'];
$data['name'] = $product_info['name'];
$data['category'] = str_replace('"', '\\"', $category_name);
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_product', $data);
// Insert the snippet after the output
$output = str_replace('</body>', $snippet . '</body>', $output);
}
public function google_dynamic_remarketing_cart(&$route, &$data, &$output) {
// In case the extension is disabled, do nothing
if (!$this->setting->get('advertise_google_status')) {
return;
}
// If we are not on the cart page, do nothing
if (!isset($this->request->get['route']) || $this->request->get['route'] != 'checkout/cart') {
return;
}
if (!$this->registry->has('googleshopping')) {
$this->loadLibrary($this->store_id);
}
if (null === $this->googleshopping->getEventSnippetSendTo()) {
return;
}
$this->load->model('catalog/product');
$this->load->model('extension/advertise/google');
$data = array();
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
$data['ecomm_totalvalue'] = $this->cart->getTotal();
$data['ecomm_prodid'] = json_encode($this->model_extension_advertise_google->getRemarketingProductIds($this->cart->getProducts(), $this->store_id));
$data['items'] = json_encode($this->model_extension_advertise_google->getRemarketingItems($this->cart->getProducts(), $this->store_id));
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_cart', $data);
// Insert the snippet after the output
$output = str_replace('</body>', $snippet . '</body>', $output);
}
public function cron($cron_id = null, $code = null, $cycle = null, $date_added = null, $date_modified = null) {
$this->loadLibrary($this->store_id);
if (!$this->validateCRON()) {
// In case this is not a CRON task
return;
}
$this->load->language('extension/advertise/google');
// Reset taxes to use the store address and zone
$this->tax->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
$this->tax->setPaymentAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
$this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
$this->googleshopping->cron();
}
protected function validateCRON() {
if (!$this->setting->get('advertise_google_status')) {
// In case the extension is disabled, do nothing
return false;
}
if (!$this->setting->get('advertise_google_gmc_account_selected')) {
return false;
}
if (!$this->setting->get('advertise_google_gmc_shipping_taxes_configured')) {
return false;
}
try {
if (count($this->googleshopping->getTargets($this->store_id)) === 0) {
return false;
}
} catch (\RuntimeException $e) {
return false;
}
if (isset($this->request->get['cron_token']) && $this->request->get['cron_token'] == $this->config->get('advertise_google_cron_token')) {
return true;
}
if (defined('ADVERTISE_GOOGLE_ROUTE')) {
return true;
}
return false;
}
}
@@ -1,6 +0,0 @@
<?php
class ControllerExtensionAnalyticsGoogle extends Controller {
public function index() {
return html_entity_decode($this->config->get('analytics_google_code'), ENT_QUOTES, 'UTF-8');
}
}
@@ -1,38 +0,0 @@
<?php
class ControllerExtensionCaptchaGoogle extends Controller {
public function index($error = array()) {
$this->load->language('extension/captcha/google');
if (isset($error['captcha'])) {
$data['error_captcha'] = $error['captcha'];
} else {
$data['error_captcha'] = '';
}
$data['site_key'] = $this->config->get('captcha_google_key');
$data['route'] = $this->request->get['route'];
return $this->load->view('extension/captcha/google', $data);
}
public function validate() {
if (empty($this->session->data['gcapcha'])) {
$this->load->language('extension/captcha/google');
if (!isset($this->request->post['g-recaptcha-response'])) {
return $this->language->get('error_captcha');
}
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('captcha_google_secret')) . '&response=' . $this->request->post['g-recaptcha-response'] . '&remoteip=' . $this->request->server['REMOTE_ADDR']);
$recaptcha = json_decode($recaptcha, true);
if ($recaptcha['success']) {
$this->session->data['gcapcha'] = true;
} else {
return $this->language->get('error_captcha');
}
}
}
}
@@ -1,12 +0,0 @@
<?php
// * @source See SOURCE.txt for source and other copyright.
// * @license GNU General Public License version 3; see LICENSE.txt
// Text
$_['text_captcha'] = 'Капча';
// Entry
$_['entry_captcha'] = 'Введите код в поле ниже';
// Error
$_['error_captcha'] = 'Неверно введен код с картинки!';
@@ -1,141 +0,0 @@
<?php
class ModelExtensionAdvertiseGoogle extends Model {
public function getHumanReadableCategory($product_id, $store_id) {
$this->load->config('googleshopping/googleshopping');
$google_category_result = $this->db->query("SELECT google_product_category FROM `" . DB_PREFIX . "googleshopping_product` pag WHERE pag.product_id = " . (int)$product_id . " AND pag.store_id = " . (int)$store_id);
if ($google_category_result->num_rows > 0) {
$google_category_id = $google_category_result->row['google_product_category'];
$google_categories = $this->config->get('advertise_google_google_product_categories');
if (!empty($google_category_id) && isset($google_categories[$google_category_id])) {
return $google_categories[$google_category_id];
}
}
$oc_category_result = $this->db->query("SELECT c.category_id FROM `" . DB_PREFIX . "product_to_category` p2c LEFT JOIN `" . DB_PREFIX . "category` c ON (c.category_id = p2c.category_id) WHERE p2c.product_id=" . (int)$product_id . " LIMIT 0,1");
if ($oc_category_result->num_rows > 0) {
return $this->getHumanReadableOpenCartCategory((int)$oc_category_result->row['category_id']);
}
return "";
}
public function getHumanReadableOpenCartCategory($category_id) {
$sql = "SELECT GROUP_CONCAT(cd.name ORDER BY cp.level SEPARATOR ' &gt; ') AS path FROM " . DB_PREFIX . "category_path cp LEFT JOIN " . DB_PREFIX . "category_description cd ON (cp.path_id = cd.category_id) WHERE cd.language_id=" . (int)$this->config->get('config_language_id') . " AND cp.category_id=" . (int)$category_id;
$result = $this->db->query($sql);
if ($result->num_rows > 0) {
return $result->row['path'];
}
return "";
}
public function getSizeAndColorOptionMap($product_id, $store_id) {
$color_id = $this->getOptionId($product_id, $store_id, 'color');
$size_id = $this->getOptionId($product_id, $store_id, 'size');
$groups = $this->googleshopping->getGroups($product_id, $this->config->get('config_language_id'), $color_id, $size_id);
$colors = $this->googleshopping->getProductOptionValueNames($product_id, $this->config->get('config_language_id'), $color_id);
$sizes = $this->googleshopping->getProductOptionValueNames($product_id, $this->config->get('config_language_id'), $size_id);
$map = array(
'groups' => $groups,
'colors' => count($colors) > 1 ? $colors : null,
'sizes' => count($sizes) > 1 ? $sizes : null,
);
return $map;
}
public function getCoupon($order_id) {
$sql = "SELECT c.code FROM `" . DB_PREFIX . "coupon_history` ch LEFT JOIN `" . DB_PREFIX . "coupon` c ON (c.coupon_id = ch.coupon_id) WHERE ch.order_id=" . (int)$order_id;
$result = $this->db->query($sql);
if ($result->num_rows > 0) {
return $result->row['code'];
}
return null;
}
public function getRemarketingProductIds($products, $store_id) {
$ecomm_prodid = array();
foreach ($products as $product) {
if (null !== $id = $this->getRemarketingProductId($product, $store_id)) {
$ecomm_prodid[] = $id;
}
}
return $ecomm_prodid;
}
public function getRemarketingItems($products, $store_id) {
$items = array();
foreach ($products as $product) {
if (null !== $id = $this->getRemarketingProductId($product, $store_id)) {
$items[] = array(
'google_business_vertical' => 'retail',
'id' => (string)$id,
'name' => (string)$product['name'],
'quantity' => (int)$product['quantity']
);
}
}
return $items;
}
protected function getRemarketingProductId($product, $store_id) {
$option_map = $this->getSizeAndColorOptionMap($product['product_id'], $store_id);
$found_color = "";
$found_size = "";
foreach ($product['option'] as $option) {
if (is_array($option_map['colors'])) {
foreach ($option_map['colors'] as $product_option_value_id => $color) {
if ($option['product_option_value_id'] == $product_option_value_id) {
$found_color = $color;
}
}
}
if (is_array($option_map['sizes'])) {
foreach ($option_map['sizes'] as $product_option_value_id => $size) {
if ($option['product_option_value_id'] == $product_option_value_id) {
$found_size = $size;
}
}
}
}
foreach ($option_map['groups'] as $id => $group) {
if ($group['color'] === $found_color && $group['size'] === $found_size) {
return $id;
}
}
return null;
}
protected function getOptionId($product_id, $store_id, $type) {
$sql = "SELECT pag." . $type . " FROM `" . DB_PREFIX . "googleshopping_product` pag WHERE product_id=" . (int)$product_id . " AND store_id=" . (int)$store_id;
$result = $this->db->query($sql);
if ($result->num_rows > 0) {
return (int)$result->row[$type];
}
return 0;
}
}
@@ -1,18 +0,0 @@
<script src="//www.google.com/recaptcha/api.js" type="text/javascript"></script>
<fieldset>
<legend>{{ text_captcha }}</legend>
<div class="form-group required">{% if route|slice(0, 9) == 'checkout/' %}
<label class="control-label" for="input-payment-captcha">{{ entry_captcha }}</label>
<div id="input-payment-captcha" class="g-recaptcha" data-sitekey="{{ site_key }}"></div>
{% if error_captcha %}
<div class="text-danger">{{ error_captcha }}</div>
{% endif %}
{% else %}
<label class="col-sm-2 control-label">{{ entry_captcha }}</label>
<div class="col-sm-10">
<div class="g-recaptcha" data-sitekey="{{ site_key }}"></div>
{% if error_captcha %}
<div class="text-danger">{{ error_captcha }}</div>
{% endif %}</div>
{% endif %}</div>
</fieldset>