Skip to main content

Posts

Showing posts from April, 2018

Magento 2.1.6 Product Grid page count and record count issue when programmatically adding filter using different methods

I have found a method that works. It seems that the Category view, regardless of a filter being applied or not, will  ALWAYS  use the Catalog Search module. Knowing that, we can override the following class to add a custom filter. Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection   But it's not that simple, first we have to create a custom filter in an xml document. Here are the steps: Step 1 Create a search_request.xml file in  Company/RegionManager/etc/search_request.xml . For my example I used the following code, you can replace any instance of deal_active with your custom attribute. Including the $deal_active$ <?xml version="1.0"?> <requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">  <request query="catalog_view_container" index="catalogsearch_fulltext">         <queries>            

Magento How do I enable free shipping in backend only (for order entry)

1>  Override or your custom shipping method file        app/code/core/Mage/Shipping/Model/Carrier/Freeshipping.php       or        app/code/local/ YourCompany/NewModule/Model/Carrier/ShippingMethod.php 2> You can find      public function collectRates(Mage_Shipping_Model_Rate_Request $request)   And add below two code in function          if (!Mage::app()->getStore()->isAdmin())) {             return false;         }      after below these two lines         if (!$this->getConfigFlag('active')) {             return false;         } And set to active in backend You can place the code in local if you dont want to overwrite the core This should work

If you want discount sorting in product list page(category page)

1> First need to create discount attribute for products. 2> After creation that copy  app/code/core/Mage/Catalog/Mo del/Resource/Product/collection.php in local folder app/code/local/Mage/Catalog/Mo del/Resource/Product/collection.php open the file find below bit of code around 1572      if ($attribute == 'price' && $storeId != 0) {             $this->addPriceData();             $this->getSelect()->order("price_index.min_price {$dir}");             return $this;         } after that Add below code if ($attribute == 'discount') {             //determine the discount percent value             $this->addExpressionAttributeT oSelect('discount', '(({{price}} - special_price) / {{price}})', array('price'));             //sort by the discount percent value             $sortDir = $dir;             //in case you need to reverse the order so when you sort ascending you will see the most discount

magento2 get all customizable option from products

create test file in root directory and place the below code excute it with domain/test.php <?php     //THis is test     echo '<pre>';     error_reporting(0);     ini_set('display_errors', 1);     use Magento\Framework\App\Bootstrap;     include('app/bootstrap.php');     $bootstrap = Bootstrap::create(BP, $_SERVER);     $objectManager = $bootstrap->getObjectManager();     $url = \Magento\Framework\App\ObjectManager::getInstance();     $storeManager = $url->get('\Magento\Store\Model\StoreManagerInterface');     $websiteId = $storeManager->getWebsite()->getWebsiteId();     $state = $objectManager->get('\Magento\Framework\App\State');     $state->setAreaCode('frontend');     //$product = $objectManager->get('\Magento\Catalog\Model\Product')->load('2331');     $productCollection = $objectManager-     >create('Magento\Catalog\Model\ResourceModel\Product\Collection

Create custom option programmatically in magento2

Create test.php file magento2 root directory and copy below code <?php echo '<pre>'; error_reporting(0); ini_set('display_errors', 1); use Magento\Framework\App\Bootstrap; include('app/bootstrap.php'); $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $url = \Magento\Framework\App\ObjectManager::getInstance(); $storeManager = $url->get('\Magento\Store\Model\StoreManagerInterface'); $websiteId = $storeManager->getWebsite()->getWebsiteId(); $state = $objectManager->get('\Magento\Framework\App\State'); $state->setAreaCode('frontend'); $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/importmissingorders.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); //die("here"); $productId = 2; $product = $objectManager->create('\Magento\Catalog\Model\Product')->load($productId); $values = [