Magento: Blocks on home page not shown after version upgrade? - magento

I updated my Magento from 1.9.0.1 to 1.9.2.2 recently and 2 blocks are not shown after the update. This is the code in home CMS:
{{block type="catalog/navigation" name="catalog.category" template="catalog/category/cat_list.phtml"}}
{{block type="filterproducts/latest_home_list" template="callthis/filterproducts/list.phtml"}}
Any idea why they are not there after the update? The template files are there so that can not be the reason. I debugged the code and it seems its not going into the template files so I guess thats the reason, but why isnt it going there?
Thanks!

the 1.9.2.2 version includes the SUPEE-6788 security patch, which fixes a vulnerability that allows access to private information. That means that the blocks used in CMS pages and emails must be whitelisted.
By default, only the core/template and catalog/product_new blocks types are allowed. To use other (in your case catalog/navigation and filterproducts/latest_home_list) you have to whitelist them.
To do that you simply need to include these in the permission_block table. You can do that by directly insert them in the db, or by using a setup script, which would look like:
<?php
/** #var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
$installer->getConnection()->insertMultiple(
$installer->getTable('admin/permission_variable'),
array(
array('variable_name' => 'xml_path/custom/variable', 'is_allowed' => 1),
)
);
$installer->getConnection()->insertMultiple(
$installer->getTable('admin/permission_block'),
array(
array('block_name' => 'catalog/navigation', 'is_allowed' => 1),
array('block_name' => 'filterproducts/latest_home_list', 'is_allowed' => 1)
)
);
$installer->endSetup();
note that the first part of this setup is to allow custom config variables, you don't need them for your current problem, I just include it for the sake of completeness.
You can find more information about what the patch do in magento's website

This is cause by one of the patch of your update.
Quick fix:
Find the table permission_block in the database
Add rows with catalog/navigation and filterproducts/latest_home_list to allow these blocks to show.
Empty your cache
More documentation abour this update:
http://magento.com/security/patches/supee-6788
http://magento.com/security/patches/supee-6788-technical-details
https://magento.stackexchange.com/questions/87214/how-to-check-which-modules-are-affected-by-security-patch-supee-6788/87262#87262

Related

Theme is caching previous user name

We are using CAS to login to our Drupal instance. This is working correctly and displaying the correct user content (blocks etc. based on roles). What is not working correctly is the small snippet in the theme that says welcome . It keeps showing the previous user who logged in.
How do I set this in bigpipe?
The code looks like this in the theme: <span id="user_name">{{user.displayname}}</span>
Is there a way to tell bigpipe not to cache this?
This code snippet is on one of our twig files header.twig.html which is a partial.
I ended up putting this in a block, and just referencing the block section in the theme instead of just pulling that, then I used the block to be ignored for caching.
Thanks!
I used this post with other resources to solve a similar problem. We were including {{ user.displayname }} in a twig template for the header on all pages of our site. Some users were seeing other users' names in the header after signing in. We wanted to solve the problem while impacting caching as little as possible. Here, I share in detail what we did in the hope that it will help others. I'll use the specific names used in our code. Readers will need to adjust to their own names. (The code follows our prescribed format, so please forgive that it isn't standard.)
Step 1
Create a custom module. Custom module creation is covered adequately in other places, so I won't give details here. Our custom module is named rsc.
Step 2
Create the folder modules/custom/rsc/src/Plugin/Block and in it create a file named DisplayName.php.
Step 3
In the file DisplayName.php, include the following:
<?php
namespace Drupal\rsc\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\user\Entity\User;
/**
* A block to show the user's display name
*
* #Block(
* id = "display_name",
* admin_label = "Display Name"
* )
*/
class DisplayName extends BlockBase // The class name must match the filename
{
public function build()
{
$user = User::load(\Drupal::currentUser()->id());
return
[
'#type' => 'markup',
'#markup' => $user->getDisplayName(),
'#cache' => ['contexts' => ['user']]
];
}
}
Step 4
Clear the Drupal cache to make the new block available at Block Layout.
Step 5
Go to Admin > Structure > Block Layout and place the Display Name block in the Hidden Blocks For Referencing - Not Displayed section (bottom of the list on our site). In the Configure Block dialog, edit the Machine name to display_name to match id in the code above. Clear the Display title checkbox and save. Doing this makes the block available for use in twig templates.
Step 6
In the twig template for the header, replace
{{ user.displayname }}
with
{{ drupal_entity('block', 'display_name') }}
The drupal_entity function is part of the twig_tweak module, which we were already using. It allows insertion of a custom block into a twig template. If you're not using this module, you'll need to install it, or find another method of including a block in a twig template.
Step 7
Clear the Drupal cache to make the modified template take effect.
If you see anything about this that can be improved, please comment.

CS-Cart new template for Product Filters block

I want to add a new template option for the product filters block.
So far, I have copied the existing original.tpl from:
templates\blocks\product_filters
and put it into:
templates\addons\my_changes\blocks\product_filters
then I've renamed the file to: example.tpl and edited the top line of the file to be:
{** block-description:example **}
This basic process has worked for other blocks but not for this product filters one. The only options available in the template list are 'Original', and 'Horizontal filters'.
Is there something special I need to do to make my new template show up?
Templates available to be used by blocks are defined at schema, which is located at "app/schemas/block_manager/blocks.php" file.
Usually schema contains a path to a directory containing all templates that can be used by a block, like it's done for the "products" block:
'templates' => 'blocks/products',
Which makes block manager search templates at design/themes/[theme name]/templates/blocks/products directory.
Unfortunately, by some reasons the schema of the "product_filters" block is inconsistent compared to other block schemas - it contains the list of a concrete templates to be used:
'templates' => array(
'blocks/product_filters/original.tpl' => array(),
'blocks/product_filters/selected_filters.tpl' => array(),
'blocks/product_filters/horizontal_filters.tpl' => array(),
),
Because of that, no directory scan is being performed at a moment of determining a list of templates available for a block.
This is why the approach you're using worked for other blocks but not for "product_filters".
The solution for you is simple - you should create a "app/addons/my_changes/schemas/block_manager/blocks.post.php" file with the following content:
<?php
$schema['product_filters']['templates'] = 'blocks/product_filters';
return $schema;
After that please clear the cache and make sure that the "my_changes" add-on is installed and enabled.
Thanks for pointing out this problem, we'll fix it in an upcoming releases.

When does Magento consider a cart to be abandoned? Where's that time limit set?

If left to default settings, what circumstances would have to occur for Magento 1.7 to consider a cart abandoned? Where is the code that makes this determination located?
I know that this is probably set somewhere in the quote, but I can't find it for the life of me.
I've done some Googling, but like so many Magento questions I'm left empty handed. Thanks!
As you probably know the setting is located here:
Admin => system => Configuration => Sales => Checkout => Shopping Cart => Quote Lifetime (days)
This will add the setting to the database (core_config_data table) with path:
checkout/cart/delete_quote_after
This path is used in the code on:
app/code/core/Mage/Sales/Model/Observer.php line 54
So when someone is adding something to a cart it will be updated. When a customer logs in and his cart is there it will be updated. When a cart is not updated for the last 30 days. It will be removed.
Extra information:
In case you wonder when this code is used, It is used by the cronjob of magento.
check:
App/code/core/Mage/Sales/etc/config.xml line 1732
<crontab>
<jobs>
<sales_clean_quotes>
<schedule>
<cron_expr>0 0 * * *</cron_expr>
</schedule>
<run>
<model>sales/observer::cleanExpiredQuotes</model>
</run>
</sales_clean_quotes>
Hope this helps.
The question was about when a cart becomes abandoned, not when the quote expires. As Magento doesn't have abandoned cart functionality, it's arbitrary. The various extensions to add it let you set it.
In our e-commerce we've overridden the method cleanExpiredQuotes inside app/code/core/Mage/Sales/Model/Observer.php
Our business rule looks like this:
$quotes = Mage::getModel('sales/quote')->getCollection();
$quotes->addFieldToFilter('created_at', array('to' => date("Y-m-d", time() - $lifetime)));
$quotes->addFieldToFilter('is_active', 1);
foreach ($this->getExpireQuotesAdditionalFilterFields() as $field => $condition) {
$quotes->addFieldToFilter($field, $condition);
}
$quotes->walk('delete');

magento detecting product page programmatically

On an observer file I need to detect if the loaded page corresponds to a product. I've been using a similar method to the one used on the checked answer on this question:
if (!(Mage::registry('current_product'))) return;
But until now we were testing on development. From today we are testing on pre-production servers, with lot of modules and plugins. Until now it worked seamesly but now it does not work, it does not detect when a product page is loaded. I think is related with the url rewrite to show a more "friendly" url's but can not detect how to solve it. I took a look into Alan Storm tutorial In Depth Magento Dispatch but I still can get what is wrong or what do I need to change.
Any idea? Or some other solution on how to detect when a product page is loaded?
You've verified that the observer is being hit? Make sure that for the event you are triggering on has a unique name for that event. For example in the following code the name "catalog_product_set_price" must be unique in regards to "catalog_product_load_after" event. I'm assuming you're getting into the observer, but just in case. This risk becomes possible if you add a bunch of new modules to an instance.
<catalog_product_load_after>
<observers>
<catalog_product_set_price>
<type>singleton</type>
<class>NamespaceModule_Model_Observer</class>
<method>set_price2</method>
</catalog_product_set_price>
</observers>
</catalog_product_load_after>
You could use the following array to check where you are:
$currentPageArray = array(
'request_string'=> Mage::app()->getFrontController()->getRequest()->getRequestString(),
'uri' => Mage::app()->getFrontController()->getRequest()->getRequestUri(),
'route' => Mage::app()->getFrontController()->getRequest()->getRouteName(),
'action' => Mage::app()->getFrontController()->getRequest()->getActionName(),
'controller' => Mage::app()->getFrontController()->getRequest()->getControllerName()
);
it will output something like:
Array
(
[request_string] => /some-category/some-product-page-url.html
[uri] => /catalog/product/view/id/64806/category/17
[route] => catalog
[action] => view
[controller] => product
)
You could try a different observer.
controller_action_layout_render_before_catalog_product_view
controller_action_postdispatch_catalog_product_view

add custom field to onepage checkout in magento

I'm trying to add custom fields to magento checkout onepage.
I followed an example that doesn't work in 1.4.1 because of the move to a flat order table(I think) http://inchoo.net/ecommerce/magento/adding-a-new-tab-under-one-page-checkout-full-working-module/
I can see my custom tab in checkout page with my custom fields but I can't save the fields to the database.
How do I add columns to the quote and order tables?
should this go to Mymod/sql/mymod_setup/mysql4-install-0.1.0.php or somewhere else?
How do I save the field to the db?
Do I need to save it to the quote first?
Do I use observer or something else?
Do I need to have element in my module's config.xml?
http://www.magentocommerce.com/boards/viewthread/19344/
Thanks
Disclaimer: I have not touched Magento for 6 months.
Now this is said, if you look in the app/code/core/Mage/Sales/sql/sales_setup/ directory you will find examples of how to modify order tables. For instance here is the content of app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.12-0.9.13.php (without header comments):
$installer = $this;
/* #var $installer Mage_Sales_Model_Mysql4_Setup */
$installer->addAttribute('quote', 'subtotal', array('type'=>'decimal'));
$installer->addAttribute('quote', 'base_subtotal', array('type'=>'decimal'));
$installer->addAttribute('quote', 'subtotal_with_discount', array('type'=>'decimal'));
$installer->addAttribute('quote', 'base_subtotal_with_discount', array('type'=>'decimal'));
$this is initialized from what is found in the app/code/core/Mage/Sales/etc/config.xml following the config/global/resources/sales_setup/setup/class look into this class and you'll see it inherits from Mage_Eav_Model_Entity_Setup, the default setup class, and overrides or add some methods (for flat table support for instance).
To answer your first point (first question), you can add columns by using the addAttribute() method of this class. And the answer to the second question is yes, but you have to specify in the config.xml file of your module that you want to use Mage_Sales_Model_Mysql4_Setup as setup class. This is done by adding the same xml element found in app/code/core/Mage/Sales/etc/config.xml previously (replace sales_setup with yourmod_setup). So you dump your database, you check it works by using get_class($this) in your mysql4-install-0.1.0.php file, and then you restore your db. And you continue writing in your setup file, inspiring yourself from what you see in the files in app/code/core/Mage/Sales/sql/sales_setup and it should be fine!
Now for the second point... I don't know... I hope it'll work automatically!
Good luck!

Resources