Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Magento
/app/etc/local.xml
/downloader/
/var/
/media/
maintenance.flag
togglehints.php
.sass-cache
.idea/
test.php
10 changes: 10 additions & 0 deletions app/code/local/Training/Catalog/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Created by PhpStorm.
* User: ezequiel
* Date: 05/12/15
* Time: 00:55
*/
class Training_Catalog_Helper_Data extends Mage_Core_Helper_Abstract {

}
20 changes: 20 additions & 0 deletions app/code/local/Training/Catalog/Model/Core/Url.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class Training_Catalog_Model_Core_Url
extends Mage_Core_Model_Url
{

public function getUrl($routePath = null, $routeParams = null)
{
$categoryPath = Mage::getStoreConfig('training/product/path');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tene en cuenta que todos los productos de las categorias obtienen su URL con el método getProductUrl()
Si bien esto esta resolviendo el requerimiento todas las url del sitio pasan x esta validación y no es muy performante.

if(Mage::helper('catalog')->isCategory() && $routePath == $categoryPath){
$categoryParam = Mage::getStoreConfig('training/product/category_param');
$category = Mage::registry('current_category');
$categoryId = $category->getId();
if($categoryId && !empty($categoryParam)){
$routeParams[$categoryParam] = $categoryId;
}
}
return parent::getUrl($routePath, $routeParams);
}
}
32 changes: 32 additions & 0 deletions app/code/local/Training/Catalog/Model/Observer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

class Training_Catalog_Model_Observer
{
public function catalogProductSaveAfter(Varien_Event_Observer $observer)
{
$session = Mage::getSingleton('admin/session');
if(!$session->isLoggedIn()){
return;
}
$user = $session->getUser();
$name = $user->getFirstname() . ' ' . $user->getLastname();
$product = $observer->getProduct();
$id = $product->getId();
$datetime = new DateTime();
$formatedTime = $datetime->format('d/m/Y H:i:s');
$log = sprintf('productId: "%s", user: "%s", time: "%s"', $id, $name, $formatedTime);
Mage::log( $log, LOG_INFO, 'product.log', true);
}

public function controllerActionPredispatchCatalogProductFeed(Varien_Event_Observer $observer)
{
$controllerAction = $observer->getControllerAction();
$productId = $controllerAction->getRequest()->getParam('id');
$product = Mage::getModel('catalog/product')->load($productId);
$visibility = $product->getVisibility();
$visibilityStates = Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds();
if(!in_array( $visibility, $visibilityStates)){
$controllerAction->norouteAction();
}
}
}
64 changes: 64 additions & 0 deletions app/code/local/Training/Catalog/etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0"?>
<config>
<modules>
<Training_Catalog>
<version>0.1.0</version>
</Training_Catalog>
</modules>
<global>
<models>
<training_catalog>
<class>Training_Catalog_Model</class>
</training_catalog>
<core>
<rewrite>
<url>Training_Catalog_Model_Core_Url</url>
</rewrite>
</core>
</models>
<blocks>
<training_catalog>
<class>Training_Catalog_Block</class>
</training_catalog>
</blocks>
<helpers>
<training_catalog>
<class>Training_Catalog_Helper</class>
</training_catalog>
</helpers>
<resources>
<training_catalog_setup>
<setup>
<module>Training_Catalog</module>
</setup>
</training_catalog_setup>
</resources>
<events>
<catalog_product_save_after>
<observers>
<training_catalog_catalog_product_save_after>
<type>singleton</type>
<class>training_catalog/observer</class>
<method>catalogProductSaveAfter</method>
</training_catalog_catalog_product_save_after>
</observers>
</catalog_product_save_after>
<controller_action_predispatch_catalog_product_feed>
<observers>
<training_controller_action_predispatch_catalog_product_feed>
<class>training_catalog/observer</class>
<method>controllerActionPredispatchCatalogProductFeed</method>
</training_controller_action_predispatch_catalog_product_feed>
</observers>
</controller_action_predispatch_catalog_product_feed>
</events>
</global>
<default>
<training>
<product>
<path>catalog/product/view</path>
<category_param>cat</category_param>
</product>
</training>
</default>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();

$config = new Mage_Core_Model_Config();
$config->saveConfig('dev/log/active', 1);

$installer->endSetup();
9 changes: 9 additions & 0 deletions app/etc/modules/Training_Catalog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<config>
<modules>
<Training_Catalog>
<active>true</active>
<codePool>local</codePool>
</Training_Catalog>
</modules>
</config>