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 23, 2023
2 parents 66c2c20 + b4cee73 commit 4feffa3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
/phpstan.dist.issues.neon export-ignore
/phpstan.dist.neon export-ignore

/README.md export-ignore

# Enforce checkout with linux lf consistent over all platforms
*.html text eol=lf
*.css text eol=lf
Expand Down
5 changes: 5 additions & 0 deletions app/code/core/Mage/Cron/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ protected function _processJob($schedule, $jobConfig, $isAlways = false)
$schedule->setStatus($errorStatus)
->setMessages($e->__toString());
}

if ($schedule->getIsError()) {
$schedule->setStatus(Mage_Cron_Model_Schedule::STATUS_ERROR);
}

$schedule->save();

return $this;
Expand Down
9 changes: 9 additions & 0 deletions app/code/core/Mage/Cron/Model/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @method Mage_Cron_Model_Resource_Schedule _getResource()
* @method Mage_Cron_Model_Resource_Schedule getResource()
* @method Mage_Cron_Model_Resource_Schedule_Collection getCollection()
* @method $this setIsError(bool $value)
* @method string getJobCode()
* @method $this setJobCode(string $value)
* @method string getStatus()
Expand Down Expand Up @@ -53,6 +54,14 @@ public function _construct()
$this->_init('cron/schedule');
}

/**
* @return bool
*/
public function getIsError(): bool
{
return !empty($this->getData('is_error'));
}

/**
* @param string $expr
* @return $this
Expand Down
46 changes: 23 additions & 23 deletions app/code/core/Mage/GoogleAnalytics/Block/Ga.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,9 @@ protected function _getOrdersTrackingCodeAnalytics4()
if ($_removedProduct->getAttributeText('manufacturer')) {
$_item['item_brand'] = $_removedProduct->getAttributeText('manufacturer');
}
if ($_removedProduct->getCategoryIds()) {
$_lastCat = end($_removedProduct->getCategoryIds());
$_cat = Mage::getModel('catalog/category')->load($_lastCat);
$_item['item_category'] = $_cat->getName();
$itemCategory = Mage::helper('googleanalytics')->getLastCategoryName($_removedProduct);
if ($itemCategory) {
$_item['item_category'] = $itemCategory;
}
array_push($eventData['items'], $_item);
$result[] = "gtag('event', 'remove_from_cart', " . json_encode($eventData, JSON_THROW_ON_ERROR) . ");";
Expand Down Expand Up @@ -297,10 +296,10 @@ protected function _getOrdersTrackingCodeAnalytics4()
if ($_addedProduct->getAttributeText('manufacturer')) {
$_item['item_brand'] = $_addedProduct->getAttributeText('manufacturer');
}
if ($_addedProduct->getCategoryIds()) {
$_lastCat = end($_addedProduct->getCategoryIds());
$_cat = Mage::getModel('catalog/category')->load($_lastCat);
$_item['item_category'] = $_cat->getName();

$itemCategory = Mage::helper('googleanalytics')->getLastCategoryName($_addedProduct);
if ($itemCategory) {
$_item['item_category'] = $itemCategory;
}
array_push($eventData['items'], $_item);
$result[] = "gtag('event', 'add_to_cart', " . json_encode($eventData, JSON_THROW_ON_ERROR) . ");";
Expand Down Expand Up @@ -398,14 +397,15 @@ protected function _getOrdersTrackingCodeAnalytics4()
'item_id' => $_product->getSku(),
'item_name' => $_product->getName(),
'price' => number_format($_product->getFinalPrice(), 2),
'quantity' => (int) $productInCart->getQty(),
];
if ($_product->getAttributeText('manufacturer')) {
$_item['item_brand'] = $_product->getAttributeText('manufacturer');
}
if ($_product->getCategoryIds()) {
$_lastCat = end($_product->getCategoryIds());
$_cat = Mage::getModel('catalog/category')->load($_lastCat);
$_item['item_category'] = $_cat->getName();

$itemCategory = Mage::helper('googleanalytics')->getLastCategoryName($_product);
if ($itemCategory) {
$_item['item_category'] = $itemCategory;
}
array_push($eventData['items'], $_item);
$eventData['value'] += $_product->getFinalPrice();
Expand Down Expand Up @@ -436,10 +436,10 @@ protected function _getOrdersTrackingCodeAnalytics4()
if ($_product->getAttributeText('manufacturer')) {
$_item['item_brand'] = $_product->getAttributeText('manufacturer');
}
if ($_product->getCategoryIds()) {
$_lastCat = end($_product->getCategoryIds());
$_cat = Mage::getModel('catalog/category')->load($_lastCat);
$_item['item_category'] = $_cat->getName();

$itemCategory = Mage::helper('googleanalytics')->getLastCategoryName($_product);
if ($itemCategory) {
$_item['item_category'] = $itemCategory;
}
array_push($eventData['items'], $_item);
$eventData['value'] += $_product->getFinalPrice();
Expand Down Expand Up @@ -475,18 +475,18 @@ protected function _getOrdersTrackingCodeAnalytics4()
$_item = [
'item_id' => $item->getSku(),
'item_name' => $item->getName(),
'quantity' => $item->getQtyOrdered(),
'price' => $item->getBasePrice(),
'discount' => $item->getBaseDiscountAmount()
'quantity' => (int) $item->getQtyOrdered(),
'price' => number_format($item->getBasePrice(), 2),
'discount' => number_format($item->getBaseDiscountAmount(), 2)
];
$_product = Mage::getModel('catalog/product')->load($item->getProductId());
if ($_product->getAttributeText('manufacturer')) {
$_item['item_brand'] = $_product->getAttributeText('manufacturer');
}
if ($_product->getCategoryIds()) {
$_lastCat = end($_product->getCategoryIds());
$_cat = Mage::getModel('catalog/category')->load($_lastCat);
$_item['item_category'] = $_cat->getName();

$itemCategory = Mage::helper('googleanalytics')->getLastCategoryName($_product);
if ($itemCategory) {
$_item['item_category'] = $itemCategory;
}
array_push($orderData['items'], $_item);
}
Expand Down
17 changes: 17 additions & 0 deletions app/code/core/Mage/GoogleAnalytics/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,21 @@ public function isUserIdEnabled($store = null)
{
return Mage::getStoreConfigFlag(self::XML_PATH_USERID, $store);
}

/**
* Returns last category name
*
* @param Mage_Catalog_Model_Product $product
* @return string
*/
public function getLastCategoryName($product): string
{
$_categoryIds = $product->getCategoryIds();
if ($_categoryIds) {
$_lastCat = array_pop($_categoryIds);
$_cat = Mage::getModel('catalog/category')->load($_lastCat);
return $_cat->getName();
}
return '';
}
}

0 comments on commit 4feffa3

Please sign in to comment.