diff --git a/.gitattributes b/.gitattributes index f5cfebfb1fa..a54ca6bcb41 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/app/code/core/Mage/Cron/Model/Observer.php b/app/code/core/Mage/Cron/Model/Observer.php index c61739ac26a..a133538ac8e 100644 --- a/app/code/core/Mage/Cron/Model/Observer.php +++ b/app/code/core/Mage/Cron/Model/Observer.php @@ -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; diff --git a/app/code/core/Mage/Cron/Model/Schedule.php b/app/code/core/Mage/Cron/Model/Schedule.php index f869c806cb3..5158894adab 100644 --- a/app/code/core/Mage/Cron/Model/Schedule.php +++ b/app/code/core/Mage/Cron/Model/Schedule.php @@ -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() @@ -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 diff --git a/app/code/core/Mage/GoogleAnalytics/Block/Ga.php b/app/code/core/Mage/GoogleAnalytics/Block/Ga.php index 8ff63df5a15..62cc5f09e3e 100644 --- a/app/code/core/Mage/GoogleAnalytics/Block/Ga.php +++ b/app/code/core/Mage/GoogleAnalytics/Block/Ga.php @@ -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) . ");"; @@ -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) . ");"; @@ -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(); @@ -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(); @@ -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); } diff --git a/app/code/core/Mage/GoogleAnalytics/Helper/Data.php b/app/code/core/Mage/GoogleAnalytics/Helper/Data.php index 237d2c2b0ff..7136ea224ec 100644 --- a/app/code/core/Mage/GoogleAnalytics/Helper/Data.php +++ b/app/code/core/Mage/GoogleAnalytics/Helper/Data.php @@ -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 ''; + } }