Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Jun 14, 2023
2 parents 7145d4f + f703211 commit bfabcdf
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 168 deletions.
35 changes: 35 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Make packagist / composer download smaller
/.ddev export-ignore
/.github export-ignore
/dev
/docs

/.all-contributorsrc
/.gitattributes export-ignore
/.gitignore
/.gitpod.yml

/.php-cs-fixer.dist.php export-ignore
/.phpcs.ecg.xml.dist export-ignore
/.phpcs.php.xml.dist export-ignore
/.phpcs.xml.dist export-ignore
/.phpmd.dist.xml export-ignore
/phpstan.dist.baseline.neon export-ignore
/phpstan.dist.issues.neon export-ignore
/phpstan.dist.neon export-ignore

# Enforce checkout with linux lf consistent over all platforms
*.html text eol=lf
*.css text eol=lf
*.js text eol=lf
*.json text eol=lf
*.php text eol=lf
*.md text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.xml text eol=lf
*.sh text eol=lf
*.sql text eol=lf
*.svg text eol=lf
*.txt text eol=lf
*.phtml text eol=lf
342 changes: 235 additions & 107 deletions app/code/core/Mage/GoogleAnalytics/Block/Ga.php

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions app/code/core/Mage/GoogleAnalytics/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Mage_GoogleAnalytics_Helper_Data extends Mage_Core_Helper_Abstract
public const XML_PATH_TYPE = 'google/analytics/type';
public const XML_PATH_ACCOUNT = 'google/analytics/account';
public const XML_PATH_ANONYMIZATION = 'google/analytics/anonymization';
public const XML_PATH_DEBUG = 'google/analytics/debug';
public const XML_PATH_USERID = 'google/analytics/user_id';

/**
* @var string google analytics 4
Expand Down Expand Up @@ -104,4 +106,37 @@ public function isUseAnalytics4($store = null)
{
return Mage::getStoreConfig(self::XML_PATH_TYPE, $store) == self::TYPE_ANALYTICS4;
}

/**
* Whether GA Debug Mode is enabled (only for development IP)
*
* @param null $store
* @return bool
*/
public function isDebugModeEnabled($store = null)
{
return Mage::getStoreConfigFlag(self::XML_PATH_DEBUG, $store) && Mage::helper('core')->isDevAllowed();
}

/**
* Log debug message
*
* @param string $message
*/
public function log($message = null)
{
$filename = sprintf('google%s.log', Mage::getStoreConfig(self::XML_PATH_TYPE));
Mage::log($message, Zend_Log::DEBUG, $filename, true);
}

/**
* Whether GA IP Anonymization is enabled
*
* @param null $store
* @return bool
*/
public function isUserIdEnabled($store = null)
{
return Mage::getStoreConfigFlag(self::XML_PATH_USERID, $store);
}
}
14 changes: 12 additions & 2 deletions app/code/core/Mage/GoogleAnalytics/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public function removeItemFromCartGoogleAnalytics(Varien_Event_Observer $observe
{
$productRemoved = $observer->getEvent()->getQuoteItem()->getProduct();
if ($productRemoved) {
Mage::getSingleton('core/session')->setRemovedProductCart($productRemoved->getId());
$_removedProducts = Mage::getSingleton('core/session')->getRemovedProductsCart() ?: [];
$_removedProducts[] = $productRemoved->getId();
$_removedProducts = array_unique($_removedProducts);
Mage::getSingleton('core/session')->setRemovedProductsCart($_removedProducts);
}
}

Expand All @@ -72,7 +75,14 @@ public function addItemToCartGoogleAnalytics(Varien_Event_Observer $observer)
{
$productAdded = $observer->getEvent()->getQuoteItem()->getProduct();
if ($productAdded) {
Mage::getSingleton('core/session')->setAddedProductCart($productAdded->getId());
// Fix double add to cart for configurable products, skip child product
if ($productAdded->getParentProductId()) {
return;
}
$_addedProducts = Mage::getSingleton('core/session')->getAddedProductsCart() ?: [];
$_addedProducts[] = $productAdded->getParentItem() ? $productAdded->getParentItem()->getId() : $productAdded->getId();
$_addedProducts = array_unique($_addedProducts);
Mage::getSingleton('core/session')->setAddedProductsCart($_addedProducts);
}
}
}
29 changes: 29 additions & 0 deletions app/code/core/Mage/GoogleAnalytics/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</account>
<user_id translate="label comment">
<label>User ID tracking</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>21</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Enable GA4 User_id tracking for logged in customers.</comment>
<depends>
<type>analytics4</type>
</depends>
</user_id>
<debug translate="label comment">
<label>Debug</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>22</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Enable GA4 Debug Real Time view for Development IP.</comment>
<depends>
<type>analytics4</type>
</depends>
</debug>
<anonymization translate="label">
<label>Enable IP anonymization</label>
<frontend_type>select</frontend_type>
Expand All @@ -65,6 +91,9 @@
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends>
<type>universal</type>
</depends>
</anonymization>
</fields>
</analytics>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ $_accountId = $_helper->getAccountId();
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?= $_accountId ?>');
<?php echo $this->_getPageTrackingCode($_accountId) ?>
<?php echo $this->_getOrdersTrackingCodeAnalytics4() ?>
</script>
<!-- END GOOGLE ANALYTICS 4 CODE -->
Expand Down
2 changes: 2 additions & 0 deletions app/locale/en_US/Mage_GoogleAnalytics.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
"Type","Type"
"Universal Analytics","Universal Analytics"
"Google Analytics 4","Google Analytics 4"
"Enable GA4 User_id tracking for logged in customers.","Enable GA4 User_id tracking for logged in customers."
"Enable GA4 Debug Real Time view for Development IP.","Enable GA4 Debug Real Time view for Development IP."
9 changes: 2 additions & 7 deletions lib/Varien/Db/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ public function __construct($config = [])
// convenience variable
$db = $config['db'];

// use an object from the registry?
if (is_string($db)) {
$db = Zend::registry($db);
}

// make sure it's a Zend_Db_Adapter
if (! $db instanceof Zend_Db_Adapter_Abstract) {
throw new Varien_Db_Tree_Exception('db object does not implement Zend_Db_Adapter_Abstract');
Expand Down Expand Up @@ -223,7 +218,7 @@ public function clear($data = [])

try {
$this->_db->insert($this->_table, $data);
} catch (PDOException $e) {
} catch (Zend_Db_Adapter_Exception $e) {
echo $e->getMessage();
}
return $this->_db->lastInsertId();
Expand Down Expand Up @@ -424,7 +419,7 @@ public function __moveNode($eId, $pId, $aId = 0)

if ($pId == 0) { //move to root
$right_key_near = $this->_db->fetchOne('SELECT MAX(' . $this->_right . ') FROM ' . $this->_table);
} elseif ($aId != 0 && $pID == $eInfo[$this->_pid]) { // if we have after ID
} elseif ($aId != 0 && $pId == $eInfo[$this->_pid]) { // if we have after ID
$right_key_near = $aInfo[$this->_right];
$left_key_near = $aInfo[$this->_left];
} elseif ($aId == 0 && $pId == $eInfo[$this->_pid]) { // if we do not have after ID
Expand Down
9 changes: 3 additions & 6 deletions lib/Varien/Db/Tree/NodeSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,10 @@ public function valid(): bool
return isset($this->_nodes[$this->_current]);
}

#[\ReturnTypeWillChange]
public function next()
public function next(): void
{
if ($this->_current > $this->_currentNode) {
return false;
} else {
return $this->_current++;
if ($this->_current <= $this->_currentNode) {
$this->_current++;
}
}

Expand Down
7 changes: 1 addition & 6 deletions lib/Varien/File/Uploader/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
*/
class Varien_File_Uploader_Image extends Varien_File_Uploader
{
public function __construct($file = null)
public function __construct()
{
register_shutdown_function([$this, 'destruct']);
$this->newUploader($file);
}

/**
Expand Down Expand Up @@ -351,7 +350,3 @@ public function setBgColor($color = "#000000")
$this->uploader->image_background_color = $color;
}
}

// ft:php
// fileformat:unix
// tabstop:4
3 changes: 0 additions & 3 deletions lib/Varien/Filter/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ public function filter($value)
foreach ($constructions as $index => $construction) {
$replacedValue = '';
$callback = [$this, $directive];
if (!is_callable($callback)) {
continue;
}
try {
$replacedValue = call_user_func($callback, $construction);
} catch (Exception $e) {
Expand Down
35 changes: 0 additions & 35 deletions phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4800,41 +4800,6 @@ parameters:
count: 1
path: lib/Varien/Db/Statement/Pdo/Mysql.php

-
message: "#^Call to static method registry\\(\\) on an unknown class Zend\\.$#"
count: 1
path: lib/Varien/Db/Tree.php

-
message: "#^Dead catch \\- PDOException is never thrown in the try block\\.$#"
count: 1
path: lib/Varien/Db/Tree.php

-
message: "#^Undefined variable\\: \\$pID$#"
count: 1
path: lib/Varien/Db/Tree.php

-
message: "#^Method Varien_Db_Tree_NodeSet\\:\\:next\\(\\) with return type void returns false but should not return anything\\.$#"
count: 1
path: lib/Varien/Db/Tree/NodeSet.php

-
message: "#^Method Varien_Db_Tree_NodeSet\\:\\:next\\(\\) with return type void returns mixed but should not return anything\\.$#"
count: 1
path: lib/Varien/Db/Tree/NodeSet.php

-
message: "#^Call to an undefined method Varien_File_Uploader_Image\\:\\:newUploader\\(\\)\\.$#"
count: 1
path: lib/Varien/File/Uploader/Image.php

-
message: "#^Call to function is_callable\\(\\) with array\\{\\$this\\(Varien_Filter_Template\\), 'dependDirective'\\|'ifDirective'\\} will always evaluate to true\\.$#"
count: 1
path: lib/Varien/Filter/Template.php

-
message: "#^Right side of && is always false\\.$#"
count: 1
Expand Down

0 comments on commit bfabcdf

Please sign in to comment.