My code for payment method only whose customer group 9,
<?php
class Gta_FilterPaymentGateway_Model_Observer
{
public function paymenter(Varien_Event_Observer $observer)
{
$currentCustomerGroup = (int)Mage::getSingleton('customer/session')->getCustomerGroupId();
if (($observer->getMethodInstance()->getCode() == 'paytm_cc') && ($currentCustomerGroup !== 9))
{
$result = $observer->getResult();
$result->isAvailable = false;
}
}
}Here how can i include the guest customers in if condition?
Workout :
<?php
class Gta_FilterPaymentGateway_Model_Observer
{
public function paymenter(Varien_Event_Observer $observer)
{
$currentCustomerGroup = (int)Mage::getSingleton('customer/session')->getCustomerGroupId();
$checkcustomer = Mage::getSingleton('customer/session')->isLoggedIn();
if (($observer->getMethodInstance()->getCode() == 'paytm_cc') && ($currentCustomerGroup !== 9) && $checkcustomer )
{
$result = $observer->getResult();
$result->isAvailable = false;
}
}
}Any help thanks
Hello @Aveeva
The guest customer's group ID is 0.
So, you can use OR condition to add the required condition.
@Sanjay Jethva Is it correct
<?php
class Gta_FilterPaymentGateway_Model_Observer
{
public function paymenter(Varien_Event_Observer $observer)
{
$currentCustomerGroup = (int)Mage::getSingleton('customer/session')->getCustomerGroupId();
// $Isloggedin = Mage::getSingleton('customer/session')->isLoggedIn();
if (($observer->getMethodInstance()->getCode() == 'paytm_cc') && ($currentCustomerGroup !== 9) && ($currentCustomerGroup == 0) )
{
$result = $observer->getResult();
$result->isAvailable = false;
}
}
}
My test severs getting the issue, can't able to test, that's what asking, is it right?
<?php
class Gta_FilterPaymentGateway_Model_Observer
{
public function paymenter(Varien_Event_Observer $observer)
{
$currentCustomerGroup = (int)Mage::getSingleton('customer/session')->getCustomerGroupId();
// $Isloggedin = Mage::getSingleton('customer/session')->isLoggedIn();
if (($observer->getMethodInstance()->getCode() == 'paytm_cc') && ($currentCustomerGroup !== 9) && ($currentCustomerGroup == 0) )
{
$result = $observer->getResult();
$result->isAvailable = false;
}
}
}Not working
@Sanjay Jethva If i use or (||) condition, guest customer can see only PayTm, i need guest customers see only remaining payment method. Any help thanks
<?php
class Gta_FilterPaymentGateway_Model_Observer
{
public function paymenter(Varien_Event_Observer $observer)
{
$currentCustomerGroup = (int)Mage::getSingleton('customer/session')->getCustomerGroupId();
// $Isloggedin = Mage::getSingleton('customer/session')->isLoggedIn();
if (($observer->getMethodInstance()->getCode() == 'paytm_cc') && ($currentCustomerGroup !== 9) || ($currentCustomerGroup == 0))
{
$result = $observer->getResult();
$result->isAvailable = false;
}
}
}
@Sanjay Jethva Any help to prepare if condition?
Hello again @Aveeva
Replace the condition:
$currentCustomerGroup == 0
with:
$currentCustomerGroup != 0
Thank you.
@Sanjay Jethva Code :
<?php
class Gta_FilterPaymentGateway_Model_Observer
{
public function paymenter(Varien_Event_Observer $observer)
{
$currentCustomerGroup = (int)Mage::getSingleton('customer/session')->getCustomerGroupId();
if (($observer->getMethodInstance()->getCode() == 'paytm_cc') && ($currentCustomerGroup !== 9) || ($currentCustomerGroup != 0))
{
$result = $observer->getResult();
$result->isAvailable = false;
}
}
}Still, PayTm Payment showing to the guest customer? How to restrict guest customer.
Hello @Aveeva
Check this:
if (($observer->getMethodInstance()->getCode() == 'paytm_cc') && ($currentCustomerGroup !== 9) && ($currentCustomerGroup != 0))
Thanks.
@Sanjay Jethva First thank you, one more help pls. Just guide not code help. I am facing PayPal error,
Error :
Fatal error: Uncaught Error: Call to a member function getId() on null in /var/www/html/test/app/code/Magento/Paypal/Model/Api/Nvp.php:1524
File Location :
app/code/Magento/Paypal/Model/Api
And my function :
protected function _applyStreetAndRegionWorkarounds(DataObject $address)
{
// merge street addresses into 1
if ($address->getData('street2') !== null) {
$address->setStreet(implode("\n", [$address->getData('street'), $address->getData('street2')]));
$address->unsetData('street2');
}
// attempt to fetch region_id from directory
if ($address->getCountryId() && $address->getRegion()) {
$regions = $this->_countryFactory->create()->loadByCode(
$address->getCountryId()
)->getRegionCollection()->addRegionCodeOrNameFilter(
$address->getRegion()
)->setPageSize(
1
);
$regionItems = $regions->getItems();
$region = array_shift($regionItems);
$address->setRegionId($region->getId());
$address->setExportedKeys(array_merge($address->getExportedKeys(), ['region_id']));
}
}The point is, for the issue i want to update the following code,
protected function _applyStreetAndRegionWorkarounds(DataObject $address)
{
// merge street addresses into 1
if ($address->getData('street2') !== null) {
$address->setStreet(implode("\n", [$address->getData('street'), $address->getData('street2')]));
$address->unsetData('street2');
}
// attempt to fetch region_id from directory
if ($address->getCountryId() && $address->getRegion()) {
$regions = $this->_countryFactory->create()
->loadByCode($address->getCountryId())
->getRegionCollection()
->addRegionCodeOrNameFilter($address->getRegion())
->setPageSize(1);
if ($regions->count()) {
$regionItems = $regions->getItems();
$region = array_shift($regionItems);
$address->setRegionId($region->getId());
$address->setExportedKeys(array_merge($address->getExportedKeys(), ['region_id']));
}
}
}Complete Code : https://paste.ofcode.org/3TGVGN4kij4JEau5nVdqW8
What is the best way to overwrite?