Showing posts with label Magento. Show all posts
Showing posts with label Magento. Show all posts

Mangento 2 admin menu description

http://www.magestore.com/magento-2-tutorial/how-to-create-admin-menu-in-magento-2/

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
     <add id="Magestore_CustomMenu::menu" title="Custom Menu" module="Magestore_CustomMenu" sortOrder="10" resource="Magestore_CustomMenu::create"/>
     <add id="Magestore_CustomMenu::menu_item" title="Manage Items" module="Magestore_CustomMenu" sortOrder="10" parent="Magestore_CustomMenu::menu" action="custommenu/create/index" resource="Magestore_CustomMenu::menu_item"/>
     <add id="Magestore_CustomMenu::menu_configuration" title="Setting" module="Magestore_CustomMenu" sortOrder="20" parent="Magestore_CustomMenu::menu" action="adminhtml/system_config/edit/section/menu" resource="Magestore_CustomMenu::menu_configuration"/>
    </menu>
</config>


Attributes:
  • id: identifier of this menu. It’s a unique string and has to follow this format: [Namespace_ModuleName]::[menu_name].
  • title: the text which displays on the menu bar.
  • module: name of module, format: [Namespace_ModuleName]
  • sortOrder: define the position of the menu, the lower value will display on top of the menu.
  • parent id of parent menu
  • action: URL which is redirected when click to the menu, format: [router_name]/[controller_name]/[action_name]
  • resource uses to defined ACL rule of the user role. Admin can use it to set permissions for any users.

Magento 2 important location

Template Path Hints in Magento:
Store > Configuration > Advanced > Developer > Debug > Enabled Template Path Hints for Storefront > Yes

Security
Secret key 
Stores => Configuration => Advanced => Admin => Security => Add Secret Key to URLs

How to Call .phtml Template Only on Homepage in Magento 2

Create xml file name with /app/design/frontend/Vendor/theme/Magento_Cms/layout/cms_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="page.top">
        <block class="Magento\Framework\View\Element\Template" name="home" template="Magento_Cms::html/home.phtml">
            <arguments>
                <argument name="section" xsi:type="string">homepage</argument>
                <argument name="position" xsi:type="number">0</argument>
            </arguments>
        </block>
    </referenceContainer>
</page>


Create .phtml file in
/app/design/frontend/Vendor/theme/Magento_Cms/templates/html/home.phtml

<?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('homepage-slider')->toHtml();?>


Magento 2 - How to call a custom phtml file in another phtml file, xml layout, static block and cms page?

http://stackoverflow.com/questions/34288366/magento-2-how-to-call-a-custom-phtml-file-in-another-phtml-file-xml-layout-s


Formula: 

{{block class="[BlockClassFullName]" template="[VendorName]_[ModuleName]::[YoutTemplateFile.location].phtml"}} 

Magent all products in a cms page

In page content: 
<p>{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml" columnCount="4"}}</p>

Layout update xml

<reference name="left">           
            <block type="catalog/navigation" name="catalog.left_category_nav" after="currency" template="catalog/navigation/category_nav.phtml"/>           
           <block type="catalog/product_popular" template="catalog/product/popular_left.phtml"/>
</reference>

How to add attribute to customer entity type in Magento / custom select dropdown field in customer registration

https://gist.github.com/jreinke/1678387#file-mysql4-install-0-1-0-php-L4-L18

 <?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer', 'civility', array(
    'label'        => 'Civility',
    'visible'      => true,
    'required'     => false,
    'type'         => 'int',
    'input'        => 'select',
    'user_defined' => '1',
    'source'       => 'eav/entity_attribute_source_table',
));
$tableOptions = $installer->getTable('eav_attribute_option');
$tableOptionValues = $installer->getTable('eav_attribute_option_value');
$attributeId = (int) $installer->getAttribute('customer', 'civility', 'attribute_id');
foreach (array('Mr', 'Mrs', 'Miss') as $sortOrder => $label) {
    $data = array(
        'attribute_id' => $attributeId,
        'sort_order'   => $sortOrder,
    );
    $installer->getConnection()->insert($tableOptions, $data);
    $optionId = (int) $installer->getConnection()->lastInsertId($tableOptions, 'option_id');
    $data = array(
        'option_id' => $optionId,
        'store_id'  => 0,
        'value'     => $label,
    );
    $installer->getConnection()->insert($tableOptionValues, $data);
}
$installer->endSetup();

registration.phtml

  <li>
                    <?php
                    $attribute = Mage::getModel('eav/config')->getAttribute('customer','civility');
                    $options = $attribute->getSource()->getAllOptions();
                    ?>
                    <label for="civility" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('Civility') ?></label>
                    <div class="input-box">
                        <select name="civility" id="civility" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>">
                            <?php
                            foreach($options as $option){
                                ?>
                                <option value='<?php echo $option['value']?>' <?php if($this->getFormData()->getCivility() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option>

                            <?php } ?>
                        </select>
                    </div>
                </li>

edit.php

  <li>
                    <?php
                    $attribute = Mage::getModel('eav/config')->getAttribute('customer','civility');
                    $options = $attribute->getSource()->getAllOptions();
                    ?>
                    <label for="civility" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('Civility') ?></label>
                    <div class="input-box">
                        <select name="civility" id="civility" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>">
                            <?php
                            foreach($options as $option){
                                ?>
                                <option value='<?php echo $option['value']?>' <?php if($this->getCustomer()->getCivility() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option>

                            <?php } ?>
                        </select>
                    </div>
                </li>

http://www.blessthemoon.com/magento-eav-model-and-customer-registration-part-4-adding-a-source-model/

Customer address book in registration form

In confiq.xml add to following code
<?xml version="1.0"?>
<layout>
  <customer_account_create>
    <reference name="customer_form_register">
      <action method="setShowAddressFields"><value>1</value></action>
    </reference>
  </customer_account_create>
</layout

Context-Based URI Model Loading

Now that we're in our Action method entry point, we'll want to start instantiating classes that do things. Magento offers a special way to instantiate Models, Helpers and Blocks using static factory methods on the global Mage class. For example:
Mage::getModel('catalog/product');
Mage::helper('catalog/product');
The string 'catalog/product' is called a Grouped Class Name. It's also often called a URI. The first portion of any Grouped Class Name (in this case, catalog), is used to lookup which Module the class resides in. The second portion ('product' above) is used to determine which class should be loaded.
So, in both of the examples above, 'catalog' resolves to the Module app/code/core/Mage/Catalog.
Meaning our class name will start with Mage_Catalog.
Then, product is added to get the final class name
Mage::getModel('catalog/product');
Mage_Catalog_Model_Product

Mage::helper('catalog/product');
Mage_Catalog_Helper_Product
These rules are bound by what's been setup in each Module's config file. When you create your own custom Module, you'll have your own grouped classnames (also calles classgroups) to work with Mage::getModel('myspecialprefix/modelname');.
You don't have to use Grouped Class Names to instantiate your classes. However, as we'll learn later, there are certain advantages to doing so.

Display prices for registered users only in Magento

Price display for login user

Define observers in your module config.xml

<?xml version="1.0"?>
<config>
     <global>     
        <events>
            <catalog_product_collection_load_after>
                <observers>
                    <hide_price_list_collection>
                        <type>singleton</type>
                        <class>Invisibleman_Sample_Model_Observer</class>
                        <method>listCollection</method>
                    </hide_price_list_collection>
                </observers>
            </catalog_product_collection_load_after>
            <catalog_product_load_after>
                <observers>
                    <hide_price_product>
                        <type>singleton</type>
                        <class>Invisibleman_Sample_Model_Observer</class>
                        <method>productLoadAfter</method>
                    </hide_price_product>
                </observers>
            </catalog_product_load_after>

             <catalog_product_is_salable_after>
                <observers>
                    <addtocart_modify_saleable>
                        <type>singleton</type>
                        <class>Webalive_Customer_Model_Observer</class>
                        <method>modifySaleable</method>
                    </addtocart_modify_saleable>
                </observers>
            </catalog_product_is_salable_after>

        </events>
    </global>
</config>   

And in observer class create methods:

class Invisibleman_Sample_Model_Observer {

    public function listCollection(Varien_Event_Observer $observer)
    {
        if (!Mage::helper('customer')->isLoggedIn()) {
            $collection = $observer->getEvent()->getCollection();
            foreach ($collection->getItems() as $_item ) {
                $_item->setCanShowPrice(false);
            }
        }
        return $this;
    }

    public function productLoadAfter(Varien_Event_Observer $observer)
    {
        if (!Mage::helper('customer')->isLoggedIn()) {
            $product = $observer->getEvent()->getProduct();
            $product->setCanShowPrice(false);
        }
        return $this;
    }

    public function modifySaleable($observer){
        if (!Mage::helper('customer')->isLoggedIn()) {
            $saleable = $observer->getSalable();
            $saleable->setIsSalable(false);
        }
    }
}

Create your own Magento log files with Mage::log()

Magento comes with a built-in logging facility which can be enabled and configured in the back-end under System > Configuration > Developer. Alternatively you can enable the Developer Mode for the site to enable the log (on how to do this have a look at the index.php file). The exception log is always on.

Mage::log('My log entry');
Mage::log('My log message: '.$myVariable);
Mage::log($myArray);
Mage::log($myObject);
Mage::logException($e);





By default all log entries are appended to the var/log/system.log file and the exceptions are logged to var/log/exception.log. Objects and Arrays are automatically written via a print_r() directive. Watch out when using objects since these can get substantial in size. If you are in Developer Mode you can try if the object supports debug output via $object->debug().
Tip:
When using



Mage::log($myVariable);
If $myVariable is empty you won’t get an entry in the log. Add a comment before and at least you will know that the variable at that stage is empty:


Mage::log('My variable: '.$myVariable);

If you are distributing your own extensions it helps a lot if you don’t have to sift through heaps of unrelated log entries to identify an issue. The solution is to log to your own files.
Looking at the method definition in app/code/Mage.php you will find


public static function log($message, $level = null, $file = '') {}

so logging to your own file becomes as easy as


Mage::log('My log entry', null, 'mylogfile.log');
and et voilá all our log entries are in their own file at var/log/mylogfile.log. Exceptions can only be logged to one file

Template path hints for magento front end / back end

  1. Open the admin control panel
  2. Open the system tab and select configuration
  3. Select Main Website or Name of your website (NOT DEFAULT CONFIG) from the Current Configuration Scope drop down
  4. Select Developer on the left sidebar
  5. Open the Debug drop down
  6. Set Template Path Hints To Yes
  7. Click on Save Config to save down your changes
http://magebase.com/magento-tutorials/quick-tip-template-hints-for-the-magento-admin-area/

Can't login magento Admin with right username and password

http://stackoverflow.com/questions/2176195/cant-log-in-to-magento-admin

If you use sample data:

Change: app/etc/local.xml line 55

<session_save><![CDATA[files]]></session_save>

replace

<session_save><![CDATA[db]]></session_save>

Then: Clear browser cache

Fatal error: Class '*_Model_Resource_Setup' not found in includes\src\Mage_Core_Model_Resource_Setup.php on line 234

http://stackoverflow.com/questions/9392111/mage-checkout-model-mysql4-setup-not-found-on-magento

It looks like you are running Magento in 'compiled modus', but something went wrong. Have a look at /home/xxxxx/public_html/xxxxxx/includes/config.php. There are two define() statements in there. Comment them out and try again.

Magento Terms

Observer
The Observer pattern is a powerful tool for plugging in customizations in key flow areas without overriding core classes and their methods.


$_blockGroup is your module's name.
$_controller is the path to your grid block. 

Magento Security Patch


https://magento.com/security/best-practices/security-best-practices

Download security patch from https://www.magentocommerce.com/download as per your version and run the patch

Security Check http://magento.com/security-patch

https://magecomp.com/blog/how-to-install-supee-7405-with-or-without-ssh/
https://magentary.com/kb/install-supee-7405-without-ssh/
https://github.com/brentwpeterson/magento-patches/tree/master/CE1.9

How to Apply and Revert Magento Patches
http://devdocs.magento.com/guides/m1x/other/ht_install-patches.html
https://support.hypernode.com/knowledgebase/how-to-apply-magento-patches/


Scan your Magento shop for known security vulnerabilities
https://www.magereport.com/

How to recover a hacked Magento shop
https://support.hypernode.com/knowledgebase/recover-a-hacked-magento-shop/

Updating Magento 1
http://support.hypernode.com/knowledgebase/updating-magento1/

Updating Magento via SSH 
https://www.dwdonline.com/blog/how-to-upgrade-magento-via-ssh.html
http://support.hypernode.com/knowledgebase/updating-magento1/#Updating_Magento_via_SSH
https://www.kathirvel.com/magento-upgrading-magento-core-modules-via-ssh/
https://firebearstudio.com/blog/upgrade-to-magento-community-1-9-by-ssh.html

chmod 750 mage
./mage mage-setup .
./mage config-set preferred_state stable
./mage sync
./mage install http://connect20.magentocommerce.com/community Mage_All_Latest --force
php shell/indexer.php reindexall
rm -rf downloader/.cache/ var/cache/
 
I'm trying to upgrade my installation of Magento 1.8.0.0 to 1.9 via SSH, when I run
./mage mage-setup .
Error:
channel-add: Channel 'community' already exist!

Solution: 
in the magento directory :
./mage channel-delete community
./mage mage-setup
Then add the extension again via magento connect
and
Go to “downloader” folder and delete the file “cache.cfg”. Then go back to Magento Connect and retry

==========================
Fatal error: Call to a member function setData() on boolean in app\code\core\Mage\Adminhtml\controllers\Permissions\BlockController.php on line 113
......
PHP Fatal error: Call to a member function setData() on a non-object in Permissions/BlockController.php on line 113 - After Applying SUPEE-6788
http://magento.stackexchange.com/questions/89965/php-fatal-error-call-to-a-member-function-setdata-on-a-non-object-in-permissi

8788
https://support.hypernode.com/knowledgebase/magento-patch-supee-8788-release-1-9-3/


Brute force attacks?
https://support.hypernode.com/knowledgebase/how-to-protect-your-magento-store-against-brute-force/

Modify the existing downloader/.htaccess file and add these lines to end:
order deny,allow
deny from all
allow from x.x.x.x
 
/admin
/downloader
/rss/* such as /rss/catalog .should be disabled


A misconfigured webserver can leak cachefiles containing database passwords.
https://magentary.com/kb/securing-magento-cacheleak/ 

print("<PRE>");
echo shell_exec("sh PATCH_SUPEE-9652_v2-2017-02-07-01-18-38.sh");
print("</PRE>");
echo "Done";