Magento Admin Custom Tab in Catalog Product - magento

I have created a custom tab under catalog product, the tab is coming fine but when i click on the tab the template for the block is not loading. It echo what i type but it is not fetching the template. I write this function in a class HTC_Csvpricing_Block_Adminhtml_Catalog_Product_Tab extends Mage_Adminhtml_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface
public function _construct()
{
parent::_construct();
echo "I m here";
$this->setTemplate('csvpricing/tab.phtml');
}
Here what I write in app/design/adminhtml/default/default/layout/csvpricing.xml
<csvpricing_adminhtml_csvpricing_index>
<reference name="content">
<block type="csvpricing/adminhtml_csvpricing" name="csvpricing" />
</reference>
</csvpricing_adminhtml_csvpricing_index>
<adminhtml_catalog_product_edit>
<reference name="product_tabs">
<action method="addTab">
<name>csvpricing_tab</name>
<block>csvpricing/adminhtml_catalog_product_tab</block>
</action>
</reference>
</adminhtml_catalog_product_edit>
Please guide what I am missing.
Thanks

You can do as follow :
Module config.xml
<config>
<adminhtml>
<layout>
<updates>
<your_module>
<file>your-module.xml</file>
</your_module>
</updates>
</layout>
</adminhtml>
</config>
Create the layout XML in /app/design/adminhtml/default/default/layout/your-module.xml:
<?xml version="1.0"?>
<layout>
<adminhtml_catalog_product_edit>
<reference name="product_tabs">
<action method="addTab">
<name>your_module_some_tab</name>
<block>your_module/adminhtml_catalog_product_tab</block>
</action>
</reference>
</adminhtml_catalog_product_edit>
</layout>
Create the tab block in {your_module}/Block/Adminhtml/Catalog/Product/Tab.php:
class Your_Module_Block_Adminhtml_Catalog_Product_Tab
extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
/**
* Set the template for the block
*/
public function _construct()
{
parent::_construct();
$this->setTemplate('catalog/product/tab/some-tab.phtml');
}
/**
* Retrieve the label used for the tab relating to this block
*
* #return string
*/
public function getTabLabel()
{
return $this->__('Some Tab');
}
/**
* Retrieve the title used by this tab
*
* #return string
*/
public function getTabTitle()
{
return $this->__('Some Tab');
}
/**
* Determines whether to display the tab
* Add logic here to decide whether you want the tab to display
*
* #return bool
*/
public function canShowTab()
{
return true;
}
/**
* Stops the tab being hidden
*
* #return bool
*/
public function isHidden()
{
return false;
}
}
you need to create a data helper to support translation, if your module does not have one already.
Make the tabs template in /app/design/adminhtml/default/default/template/catalog/product/tab/some-tab.phtml:
<div class="entry-edit">
<div class="entry-edit-head">
<h4>Some Heading</h4>
</div>
<div class="fieldset fieldset-wide">
<div class="hor-scroll">
<!-- your content here -->
</div>
</div>
</div>

Related

Invalid Types of block

I've been failing, trying to add a custom block to my module.
I got the error message :
Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid type of block: Cpy\AcquisitionNumeroTelephonne\Block\Form_lb
Exception #1 (ReflectionException): Class Cpy\AcquisitionNumeroTelephonne\Block\Form_lb does not exist
Nevertheless the class is existing :
Cpy/AcquisitionNumeroTelephonne/Block/Form_lb.php
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Cpy\AcquisitionNumeroTelephonne\Block;
use Magento\Framework\App\Request\Http;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
class Form_lb extends Template
{
/**
* #var Http
*/
private $request;
/**
* DevisList constructor.
* #param Context $context
* #param Http $request
*/
public function __construct(
Context $context,
Http $request
)
{
$this->request = $request;
parent::__construct($context);
}
}
And here is the layout definition :
Cpy/AcquisitionNumeroTelephonne/view/frontend/layout/acquisition_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Formulaire acquisition</title>
</head>
<body>
<referenceContainer name="content">
<block class="Cpy\AcquisitionNumeroTelephonne\Block\Form_lb" name="formlb" template="Aims_AcquisitionNumeroTelephonne::form/lb.phtml" cacheable="false" />
</referenceContainer>
</body>
</page>
I finally figure it out. My filename wasn't respecting the PSR convention. So the name Form_lb was invalid.
I had to rename Form_lb to FormLbthen deleting the generated/ and finally bin/magento setup:upgrade

Add custom fields to payment method

I have duplicated the checkmo doing the following below
Duplicate it as follows checkmo to checkmonew. I am using Magento version 1.9.3
Step 1 : mage/payment/block/forms + info : duplicate checkmo.php to checkmonew.php (rename inside checkmo to checkmonew)
Step 2 : mage/payment/etc/config.xml + system.xml : duplicate the checkmo parts (and rename it to checkmonew)
Step 3 : mage/payment/model/method : duplicate checkmo.php to checkmonew.php (rename inside checkmo to checkmonew)
Step 4 : design/adminhtml/default/default/template/payment/form + info : duplicate checkmo.php to checkmonew.php (rename inside checkmo to checkmonew)
Step 5 : design/frontend/base/default/template/payment/form + info :
duplicate checkmo.php to checkmonew.php (rename inside checkmo to checkmonew)
Now, this all seems to work but for some reason only on the backend but checkmo shows in the frontend, no problem.
I also want to add cc type option in the new payment method. I would prefer it not to be a drop down just a selection from the list of cards which are in cc type which is used in the CC payment method.
Thanks
admin inmage
code
block - info
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* #category Mage
* #package Mage_Payment
* #copyright Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_Payment_Block_Info_Cashmonew extends Mage_Payment_Block_Info
{
protected $_payableTo;
protected $_mailingAddress;
protected function _construct()
{
parent::_construct();
$this->setTemplate('payment/info/Cashmonew.phtml');
}
/**
* Enter description here...
*
* #return string
*/
public function getPayableTo()
{
if (is_null($this->_payableTo)) {
$this->_convertAdditionalData();
}
return $this->_payableTo;
}
protected function _prepareSpecificInformation($transport = null)
{
if (null !== $this->_paymentSpecificInformation) {
return $this->_paymentSpecificInformation;
}
$transport = parent::_prepareSpecificInformation($transport);
$data = array();
if ($ccType = $this->getCcTypeName()) {
$data[Mage::helper('payment')->__('Credit Card Type')] = $ccType;
}
if ($this->getInfo()->getCcLast4()) {
$data[Mage::helper('payment')->__('Credit Card Number')] = sprintf('xxxx-%s', $this->getInfo()->getCcLast4());
}
if (!$this->getIsSecureMode()) {
if ($ccSsIssue = $this->getInfo()->getCcSsIssue()) {
$data[Mage::helper('payment')->__('Switch/Solo/Maestro Issue Number')] = $ccSsIssue;
}
$year = $this->getInfo()->getCcSsStartYear();
$month = $this->getInfo()->getCcSsStartMonth();
if ($year && $month) {
$data[Mage::helper('payment')->__('Switch/Solo/Maestro Start Date')] = $this->_formatCardDate($year, $month);
}
}
return $transport->setData(array_merge($data, $transport->getData()));
}
/**
* Enter description here...
*
* #return string
*/
public function getMailingAddress()
{
if (is_null($this->_mailingAddress)) {
$this->_convertAdditionalData();
}
return $this->_mailingAddress;
}
/**
* Enter description here...
*
* #return Mage_Payment_Block_Info_Cashmonew
*/
protected function _convertAdditionalData()
{
$details = false;
try {
$details = Mage::helper('core/unserializeArray')
->unserialize($this->getInfo()->getAdditionalData());
} catch (Exception $e) {
Mage::logException($e);
}
if (is_array($details)) {
$this->_payableTo = isset($details['payable_to']) ? (string) $details['payable_to'] : '';
$this->_mailingAddress = isset($details['mailing_address']) ? (string) $details['mailing_address'] : '';
} else {
$this->_payableTo = '';
$this->_mailingAddress = '';
}
return $this;
}
public function toPdf()
{
$this->setTemplate('payment/info/pdf/Cashmonew.phtml');
return $this->toHtml();
}
}
block - form
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* #category Mage
* #package Mage_Payment
* #copyright Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_Payment_Block_Form_Cashmonew extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('payment/form/Cashmonew.phtml');
}
}
/**
* Retrieve availables credit card types
*
* #return array
*/
public function getCcAvailableTypes()
{
$types = $this->_getConfig()->getCcTypes();
if ($method = $this->getMethod()) {
$availableTypes = $method->getConfigData('cctypes');
if ($availableTypes) {
$availableTypes = explode(',', $availableTypes);
foreach ($types as $code=>$name) {
if (!in_array($code, $availableTypes)) {
unset($types[$code]);
}
}
}
}
return $types;
}
etc - config
<?xml version="1.0"?>
<!--
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* #category Mage
* #package Mage_Payment
* #copyright Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
* #license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
-->
<config>
<modules>
<Mage_Payment>
<version>1.6.0.0</version>
</Mage_Payment>
</modules>
<global>
<models>
<payment>
<class>Mage_Payment_Model</class>
</payment>
</models>
<resources>
<payment_setup>
<setup>
<module>Mage_Payment</module>
</setup>
</payment_setup>
</resources>
<blocks>
<payment>
<class>Mage_Payment_Block</class>
</payment>
</blocks>
<payment>
<checkmonew>
<types>
<AE>
<code>AE</code>
<name>American Express</name>
<order>0</order>
</AE>
<VI>
<code>VI</code>
<name>Visa</name>
<order>10</order>
</VI>
<MC>
<code>MC</code>
<name>MasterCard</name>
<order>20</order>
</MC>
<DI>
<code>DI</code>
<name>Discover</name>
<order>30</order>
</DI>
<SM>
<code>SM</code>
<name>Maestro/Switch</name>
<order>40</order>
</SM>
<SO>
<code>SO</code>
<name>Solo</name>
<order>45</order>
</SO>
<JCB>
<code>JCB</code>
<name>JCB</name>
<order>50</order>
</JCB>
<OT>
<code>OT</code>
<name>Other</name>
<order>1000</order>
</OT>
</types>
</checkmonew>
<groups>
<offline>Offline Payment Methods</offline>
</groups>
</payment>
<payment>
<cc>
<types>
<AE>
<code>AE</code>
<name>American Express</name>
<order>0</order>
</AE>
<VI>
<code>VI</code>
<name>Visa</name>
<order>10</order>
</VI>
<MC>
<code>MC</code>
<name>MasterCard</name>
<order>20</order>
</MC>
<DI>
<code>DI</code>
<name>Discover</name>
<order>30</order>
</DI>
<SM>
<code>SM</code>
<name>Maestro/Switch</name>
<order>40</order>
</SM>
<SO>
<code>SO</code>
<name>Solo</name>
<order>45</order>
</SO>
<JCB>
<code>JCB</code>
<name>JCB</name>
<order>50</order>
</JCB>
<OT>
<code>OT</code>
<name>Other</name>
<order>1000</order>
</OT>
</types>
</cc>
<groups>
<offline>Offline Payment Methods</offline>
</groups>
</payment>
<events>
<sales_order_save_before>
<observers>
<payment_sales_order_save_before>
<class>payment/observer</class>
<method>salesOrderBeforeSave</method>
</payment_sales_order_save_before>
</observers>
</sales_order_save_before>
<sales_order_payment_save_before>
<observers>
<payment_before_save>
<class>payment/observer</class>
<method>beforeOrderPaymentSave</method>
</payment_before_save>
</observers>
</sales_order_payment_save_before>
<sales_order_status_unassign_before>
<observers>
<payment_order_status_unassign_before>
<class>payment/observer</class>
<method>beforeSalesOrderStatusUnassign</method>
</payment_order_status_unassign_before>
</observers>
</sales_order_status_unassign_before>
</events>
</global>
<frontend>
<translate>
<modules>
<Mage_Payment>
<files>
<default>Mage_Payment.csv</default>
</files>
</Mage_Payment>
</modules>
</translate>
<events>
<catalog_product_type_prepare_full_options>
<observers>
<payment_recurring_profile_prepare_options>
<class>payment/observer</class>
<method>prepareProductRecurringProfileOptions</method>
</payment_recurring_profile_prepare_options>
</observers>
</catalog_product_type_prepare_full_options>
</events>
<layout>
<updates>
<payment module="Mage_Payment">
<file>payment.xml</file>
</payment>
</updates>
</layout>
</frontend>
<adminhtml>
<translate>
<modules>
<Mage_Payment>
<files>
<default>Mage_Payment.csv</default>
</files>
</Mage_Payment>
</modules>
</translate>
</adminhtml>
<default>
<payment>
<ccsave>
<active>1</active>
<cctypes>AE,VI,MC,DI</cctypes>
<model>payment/method_ccsave</model>
<order_status>pending</order_status>
<title>Credit Card (saved)</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</ccsave>
<checkmo>
<active>1</active>
<model>payment/method_checkmo</model>
<order_status>pending</order_status>
<title>Check / Money order</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</checkmo>
<checkmonew>
<active>1</active>
<cctypes>AE,VI,MC,DI</cctypes>
<model>payment/method_checkmonew</model>
<order_status>pending</order_status>
<title>Card POS</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</checkmonew>
<free>
<active>1</active>
<model>payment/method_free</model>
<order_status>pending</order_status>
<title>No Payment Information Required</title>
<allowspecific>0</allowspecific>
<sort_order>1</sort_order>
<group>offline</group>
</free>
<purchaseorder>
<active>0</active>
<model>payment/method_purchaseorder</model>
<order_status>pending</order_status>
<title>Purchase Order</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</purchaseorder>
<banktransfer>
<active>0</active>
<model>payment/method_banktransfer</model>
<order_status>pending</order_status>
<title>Bank Transfer Payment</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</banktransfer>
<cashondelivery>
<active>0</active>
<model>payment/method_cashondelivery</model>
<order_status>pending</order_status>
<title>Cash On Delivery</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</cashondelivery>
</payment>
</default>
</config>

Custom module not working in Magento2

I have been trying to setup a basic module in Magento2, it keeps throwing 404 despite doing all the ideal changes. Below is the code related to the module. My vendor name is Chirag and module name is HelloWorld.
/var/www/html/magento2/app/code/Chirag/HelloWorld/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Chirag_HelloWorld" schema_version="0.0.1" setup_version="0.0.1">
</module>
</config>
/var/www/html/magento2/app/code/Chirag/HelloWorld/etc/frontend/route.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
<router id="standard">
<route id="helloworld" frontName="helloworld">
<module name="Chirag_HelloWorld" />
</route>
</router>
</config>
/var/www/html/magento2/app/code/Chirag/HelloWorld/Controller/Index/Index.php
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Chirag\HelloWorld\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
/**
*
*
* #return void
*/
public function execute()
{
protected $resultPageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
)
{
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
return $this->resultPageFactory->create();
}
}
}
/var/www/html/magento2/app/code/Chirag/HelloWorld/Block/HelloWorld.php
<?php
namespace Chirag\HelloWorld\Block;
class HelloWorld extends \Magento\Framework\View\Element\Template
{
}
/var/www/html/magento2/app/code/Chirag/HelloWorld/view/frontend/layout/helloworld_index_index.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Chirag\HelloWorld\Block\HelloWorld" name="helloworld" template="helloworld.phtml" />
</referenceContainer>
</body>
</page>
/var/www/html/magento2/app/code/Chirag/HelloWorld/view/frontend/templates/helloworld.phtml
<h1> test hello to Magento 2 !! </h1>
Any kind of help would be really appreciated.
First try to rename route.xml to routes.xml and see if that fixes the issue.
Next try changing your code in the controller, try change company/module names:
<?php
namespace YourCompany\ModuleName\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
return $this->resultPageFactory->create();
}
}
also in your helloworld_index_index.xml you can try changing the template decoration to:
template="YourCompany_ModuleName::templatename.phtml"
lastly you can try changing the module.xml setup_version declaration to:
setup_version="2.0.0"
I hope this helps!
Below changes led to correct answer for me :
Index controller - magento2/app/code/Chirag/HelloWorld/Controller/Index/Index.php
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Chirag\HelloWorld\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
/**
* Show Contact Us page
*
* #return void
*/
public function execute()
{
$this->_view->loadLayout();
$this->_view->getLayout()->getBlock('helloworld');
$this->_view->renderLayout();
}
}
Block - magento2/app/code/Chirag/HelloWorld/Block/Question.php
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Chirag\HelloWorld\Block;
use Magento\Framework\View\Element\Template;
/**
* Main contact form block
*/
class Question extends Template
{
/**
* #param Template\Context $context
* #param array $data
*/
public function __construct(Template\Context $context, array $data = [])
{
parent::__construct($context, $data);
$this->_isScopePrivate = true;
}
}
Layout file - magento2/app/code/Chirag/HelloWorld/view/frontend/layout/helloworld_index_index.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Chirag\HelloWorld\Block\Question" name="helloworld" template="Chirag_HelloWorld::helloworld.phtml">
</block>
</referenceContainer>
</body>
</page>
View template - magento2/app/code/Chirag/HelloWorld/view/frontend/templates/helloworld.phtml
<?php echo 'helloworld view'; ?>
<h1> Hello World </h1>
You need to follow the below steps to resolve:
You have to change route.xml to routes.xml
Run setup upgrade command:
php bin/magento s:up
Go to your_base_link/helloworld/index/index
Enjoin your result
First of all, rename route.xml to routes.xml
app/code/Chirag/HelloWorld/etc/frontend/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="helloworld" frontName="helloworld">
<module name="Chirag_HelloWorld" />
</route>
</router>
</config>
Index Controller - app/code/Chirag/HelloWorld/Controller/Index/Index.php
You can't use __construct inside the execute method and these two should be separated.
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Chirag\HelloWorld\Controller\Index;
use Magento\Framework\App\Action\Action;
class Index extends Action
{
/**
* #var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* #param \Magento\Framework\App\Action\Context $context
* #param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
)
{
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
/**
* #return mixed
*/
public function execute()
{
return $this->resultPageFactory->create();
}
}
You should use the below format when you are calling the template in layout xml.
eg: Chirag_HelloWorld::helloworld.phtml
app/code/Chirag/HelloWorld/view/frontend/layout/helloworld_index_index.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Chirag\HelloWorld\Block\HelloWorld" name="helloworld" template="Chirag_HelloWorld::helloworld.phtml" />
</referenceContainer>
</body>
</page>
app/code/Chirag/HelloWorld/Block/HelloWorld.php
<?php
namespace Chirag\HelloWorld\Block;
class HelloWorld extends \Magento\Framework\View\Element\Template
{
public function getHelloWorldText()
{
return __('Hello World');
}
}
app/code/Chirag/HelloWorld/view/frontend/templates/helloworld.phtml
<?= /* #noEscape */ $block->getHelloWorldText() ?>
Once you done run the below commands to apply the changes.
bin/magento setup:upgrade
bin/magento setup:static-content:deploy -f
bin/magento c:f
Use -f as a parameter if you are in developer mode.
Use bin/magento deploy:mode:show to check the mode.
Happy Coding!!

Magento 1.7: Adding a custom promotion

I would like to add a custom promotion condition to Magento 1.7. It should be possible to apply a promotion based on a custom attribute in the shipping address of the customer. Its actually quite basic: if the attribute is filled, the promotion should apply, not more.
It should appear as a seperate condition point of the Cart Attributes like "Shipping Postcode" or "Shipping Region"
What would help as well: How are the standard Cart Promotion conditions are implemented or where to look for more information on this topic.
I searched the internet for quite a while now, and I'm really stuck. Your help is highly appreciated!
Thx a lot
Ok, I found a more or less working solution I want to share here, in case sombody else is needing this:
I created a module, that is introducing a new Condition into the promotions. The missing peace in order to achieve this was to do it via an observer.
First the config <path to module>\etc\config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<HauteNature_FamilienkarteHessen>
<version>1.0.0</version>
</HauteNature_FamilienkarteHessen>
</modules>
<admin>
<fieldsets>
<customer_dataflow>
<building>
<billing>1</billing>
<shipping>1</shipping>
</building>
</customer_dataflow>
</fieldsets>
</admin>
<global>
<models>
<familienkartehessen>
<class>HauteNature_FamilienkarteHessen_Model</class>
</familienkartehessen>
</models>
<helpers>
<familienkartehessen>
<class>HauteNature_FamilienkarteHessen_Helper</class>
</familienkartehessen>
</helpers>
<events>
<salesrule_rule_condition_combine>
<observers>
<add_condition_to_sales_rule>
<class>familienkartehessen/observer</class>
<method>addConditionToSalesRule</method>
</add_condition_to_sales_rule>
</observers>
</salesrule_rule_condition_combine>
</events>
<resources>
<familienkartehessen_setup>
<setup>
<module>HauteNature_FamilienkarteHessen</module>
<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</familienkartehessen_setup>
</resources>
<fieldsets>
<sales_copy_order_billing_address>
<familiycarthessen><to_order>*</to_order></familiycarthessen>
</sales_copy_order_billing_address>
<sales_copy_order_shipping_address>
<familiycarthessen><to_order>*</to_order></familiycarthessen>
</sales_copy_order_shipping_address>
<sales_convert_quote_address>
<familiycarthessen><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></familiycarthessen>
</sales_convert_quote_address>
<sales_convert_order_address>
<familiycarthessen><to_quote_address>*</to_quote_address></familiycarthessen>
</sales_convert_order_address>
<customer_address>
<familiycarthessen><to_quote_address>*</to_quote_address></familiycarthessen>
</customer_address>
<checkout_onepage_billing>
<familiycarthessen><to_customer>*</to_customer></familiycarthessen>
</checkout_onepage_billing>
</fieldsets>
</global>
</config>
I think this part is hoocking it to the magento Interface:
<salesrule_rule_condition_combine>
<observers>
<add_condition_to_sales_rule>
<class>familienkartehessen/observer</class>
<method>addConditionToSalesRule</method>
</add_condition_to_sales_rule>
</observers>
</salesrule_rule_condition_combine>
Second the observer, quite simple, just adding the menu point to the UI and linking it to the condition: <path to module>\Model\Observer.php:
class HauteNature_FamilienkarteHessen_Model_Observer extends Mage_Core_Model_Abstract {
/**
* Event: salesrule_rule_condition_combine
*
* #param $observer
*/
public function addConditionToSalesRule($observer) {
$additional = $observer->getAdditional();
$conditions = (array) $additional->getConditions();
$conditions = array_merge_recursive($conditions, array(
array('label'=>Mage::helper('familienkartehessen')->__('Familienkarte Hessen'), 'value'=>'familienkartehessen/condition_familienkarte'),
));
$additional->setConditions($conditions);
$observer->setAdditional($additional);
return $observer;
}
}
And finally the custom Condition Class that actually does the work <path to module>\Model\Condition/Familienkarte.php:
class HauteNature_FamilienkarteHessen_Model_Condition_Familienkarte extends Mage_Rule_Model_Condition_Abstract {
/**
* #TODO for whatever this it, check it and afterwards document it!
*
* #return Hackathon_DiscountForATweet_Model_Condition_Tweet
*/
public function loadAttributeOptions() {
$attributes = array(
'fkhContent' => Mage::helper('familienkartehessen')->__('Familienkarte Hessen')
);
$this->setAttributeOption($attributes);
return $this;
}
/**
* #TODO for whatever this it, check it and afterwards document it!
*
* #return mixed
*/
public function getAttributeElement() {
$element = parent::getAttributeElement();
$element->setShowAsText(true);
return $element;
}
/**
* #TODO for whatever this it, check it and afterwards document it!
*
* #return string
*/
public function getInputType() {
switch ($this->getAttribute()) {
case 'fkhContent':
return 'boolean';
}
return 'string';
}
/**
* #TODO for whatever this it, check it and afterwards document it!
* #return string
*/
public function getValueElementType() {
return 'text';
}
/**
* Validate FamiliencarteHessen Rule Condition
*
* #param Varien_Object $object
*
* #return bool
*/
public function validate(Varien_Object $object) {
/* here should be something meaningful */
$address = $object;
if (!$address instanceof Mage_Sales_Model_Quote_Address) {
if ($object->getQuote()->isVirtual()) {
$address = $object->getQuote()->getBillingAddress();
}
else {
$address = $object->getQuote()->getShippingAddress();
}
}
return $this->validateAttribute(trim($address->getFamiliycarthessen()));
}
}
If anyone of you has comments on this code, I would be greatfull to hear them.
Best wishes
Andreas

make a new product active by default in magento

When duplicating a product in the backend in magento the new product status is Disabled by default. That confuses the store admins who expect the product to show on the frontend.
How can I make the product status Enabled by default?
THanks
In your custom module you need to:
in config.xml file:
<config>
<adminhtml>
<events>
<catalog_model_product_duplicate>
<observers>
<custom_catalog_product_duplicate>
<class>custom_module/observer</class>
<method>catalogModelProductDuplicate</method>
</custom_catalog_product_duplicate>
</observers>
</catalog_model_product_duplicate>
</events>
</adminhtml>
</config>
Create an observer class with method like this:
class Custom_Module_Model_Observer
{
/**
* Prepare product for duplicate action.
*
* #param Varien_Event_Observer $observer
* #return object
*/
public function catalogModelProductDuplicate(Varien_Event_Observer $observer)
{
$newProduct = $observer->getEvent()->getNewProduct();
$newProduct->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
return $this;
}
}

Resources