I am trying to enable my custom module only for a single store view but the functionality is still working for all store views.
I have the following configuration:
Main Website > (Default store view, B2B Store view)
I want to enable my module only for the B2B Store view.
I tried to did this using system.xml: Code is:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="customrfq" translate="label" sortOrder="1000">
<label>Request For Quote</label>
</tab>
<section id="customrfq" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>RFQ</label>
<tab>customrfq</tab>
<resource>CustomB2BRFQ_Module::rfq</resource>
<group id="department" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>RFQ configuration</label>
<field id="view_list" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Quotes</label>
<comment>Show request for quotes</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
Config.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<customrfq>
<department>
<view_list>1</view_list>
</department>
</customrfq>
</default>
</config>
Layout file:
<?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">
<body>
<referenceContainer name="content">
<block class="CustomB2BRFQ\Module\Block\RequestForQuoteForm" name="custom_module_form"
template="CustomB2BRFQ_Module::rfq.phtml" ifconifg="customrfq/department/view_list" cacheable="false"/>
<arguments>
<argument name="path" xsi:type="helper" helper="CustomB2BRFQ\Module\Helper\Data::getPath" translate="true" />
</arguments>
</referenceContainer>
</body>
</page>
Helper File:
<?php
/**
* Created By : Rashi Goyal
*/
namespace CustomB2BRFQ\Module\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
const PATH_FIELD = 'customrfq/department/view_list';
/**
* #var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* #param \Magento\Framework\App\Helper\Context $context
* #param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
){
$this->scopeConfig = $scopeConfig;
parent::__construct($context);
}
public function getPath()
{
return $this->scopeConfig->getValue(self::PATH_FIELD,\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
}
Please specify what's wrong with the code?
I think you have set wrong values for following properties (system.xml):
showInDefault
showInWebsite
showInStore
According to your requirement, you want functionality by store. So you have to set these properties like this:
showInDefault="0"
showInWebsite="0"
showInStore="1"
Using this, your configuration setting display only on store view.
Also You have assigned default value = 1 (config.xml)
You should use by default this:
<view_list>0</view_list>
Related
How can I implement log4php in order to log multiple classes separately?
I have the following example for classes A and B:
class A{
private $log;
private static $instance;
public static function getInstance(): Db3
{
if (!self::$instance) {
self::$instance = new self;
}
return self::$instance;
}
function __construct()
{
Logger::configure('path/to/log4php.xml');
$this->log = Logger::getLogger(__CLASS__);
}
}
and also class B:
class B{
private $log;
private static $instance;
public static function getInstance(): Db3
{
if (!self::$instance) {
self::$instance = new self;
}
return self::$instance;
}
function __construct()
{
Logger::configure('path/to/log4php.xml');
$this->log = Logger::getLogger(__CLASS__);
}
}
This is the log4php.xml config:
<configuration xmlns="http://logging.apache.org/log4php/">
<appender name="A" class="LoggerAppenderDailyFile">
<param name="file" value="/path/to/logs/%s.A.log" />
<param name="datePattern" value="Y-m-d" />
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date{Y-m-d H:i:s,u} %-15logger %-5level %msg%n" />
</layout>
</appender>
<appender name="B" class="LoggerAppenderDailyFile">
<param name="file" value="/path/to/logs/%s.B.log" />
<param name="datePattern" value="Y-m-d" />
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date{Y-m-d H:i:s,u} %-15logger %-5level %msg%n" />
</layout>
</appender>
<logger name="A"><level value="DEBUG" /><appender_ref ref="A" /></logger>
<logger name="B"><level value="DEBUG" /><appender_ref ref="B" /></logger>
</configuration>
I need log4php to log class A and class B separately but for some reason it is not working if I do this:
$a=A::getInstance();
$a->test();
$b=B::getInstance();
$b->test();
Everything gets logged in the same file, not in yyyy-mm-dd.A.log and B.log
test() only has this line: $this->log->info('this is a test') in both classes.
I wanna use php unit tests to test an endpoint.
I'm calling an endpoint from my unit test.
Within my endpoint when I say
public function __construct()
{
\Config::set('database.default', 'pgsql-master');
print_r(\Config::get('database.connections.pgsql-master.username')); // toters_testing_usr
}
I believe it's resetting my db connection and my db testing is empty.
because when I say
$env = config('app.env');
if ($env == 'production')
{
\Config::set('database.default', 'pgsql-master');
}
it worrks.
Why is this happening?
this is my phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<filter>
<whitelist>
<directory suffix=".php">app/</directory>
</whitelist>
</filter>
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener"></listener>
</listeners>
<php>
<env name="APP_ENV" value="testing"/>
<env name="API_STRICT" value="false"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="RAVEN_LEVEL" value="none"/>
<env name="MAIL_DRIVER" value="log"/>
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
<ini name="memory_limit" value="2048M" />
</php>
</phpunit>
I am using Symfony 3.4. Suddenly, whenever I try to run my tests (phpunit) in /tests, I get the following error:
RuntimeException : Unable to guess the Kernel directory.
My test class looks something like:
class PaymentCreditTest extends KernelTestCase
{
/** #var PaymentRepository */
public $paymentRepository;
/**
* {#inheritDoc}
*/
protected function setUp()
{
$this->paymentRepository = self::bootKernel()->getContainer()->get('chaku.repository.payment');
}
public function test_canRetrieveDeadFreightNetAmount()
{
/** #var Payment $payment */
$payment = $this->paymentRepository->findOneBy(['id' => 1000002]);
// just to see payment object
dump($payment);
}
}
This is what my phpunit.xml.dist looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="app/autoload.php">
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="AppKernel" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory>src/*Bundle/Resources</directory>
<directory>src/*/*Bundle/Resources</directory>
<directory>src/*/Bundle/*Bundle/Resources</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
Any help with this will be well appreciated.
I think I had the exact same issue few weeks ago, can you try adding KERNEL_DIR:
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="AppKernel" />
<server name="KERNEL_DIR" value="app/" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>
./vendor/bin/simple-phpunit -c app/ add the Appkernel directory which is app while executing the command for testing.
Symfony 3.3 automatically generated an empty test for my new controller. It lives at src/AppBundle/Tests/Controller/PairGalleryControllerTest.php
Now I want to actually run the contents. They look like this:
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/pair-gallery/1');
$content = $client->getResponse()->getContent();
$this->assertContains('NeedleShouldFail', $content);
}
... but when I run my test suite with bin/phpunit I find that all tests pass. This new test is clearly not being run.
Where do I need to register my new test in order for it to run?
====
Edit: Here is the content of my phpunit.xml.dist file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<!--
<server name="KERNEL_DIR" value="/path/to/your/app/" />
-->
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
<directory>../src/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*Bundle/Resources</directory>
<directory>../src/*Bundle/Tests</directory>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
I have a view views/detailedforms/view.html.php
defined('_JEXEC') or die;
jimport('joomla.application.component.view');
class Detailed_formViewDetailedforms extends JViewLegacy {
protected $items;
protected $pagination;
protected $state;
protected $params;
protected $form;
/**
* Display the view
*/
public function display($tpl = null) {
$app = JFactory::getApplication();
$this->state = $this->get('State');
$this->form = $this->get('Form');
var_dump($this->form);
}
and model models/forms/detailedforms.xml
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="contact" label="Detail_FORM">
<field name="name"
type="text"
id="tailor-made-name"
size="30"
description="FORM_NAME_DESC"
label="FORM_NAME_LABEL"
filter="string"
required="true"
/>
<field name="email"
type="email"
id="email"
size="30"
description="EMAIL_DESC"
label="EMAIL_LABEL"
filter="string"
validate="tailoremail"
required="true"
/>
</fieldset>
$this->form returns null. Please help, how to fix the issue.
Due to this issue, fatal error occurs in the template file.