Wednesday 5 June 2019

Product Collection with out of stock and In Stock in Magento 2

Product collection with out of stock and In stock.

use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;

$collection = $this->_productCollectionFactory->create();
        $collection->setFlag('has_stock_status_filter', true)
            ->addAttributeToSelect(array('*'))
            ->addFieldToFilter('visibility', 4)
            ->addCategoriesFilter(['eq' => $categories])
            ->addAttributeToSort('created_at', 'DESC')
            ->joinField('qty',
                'cataloginventory_stock_item',
                'qty',
                'product_id=entity_id',
                '{{table}}.stock_id=1',
                'left'
            )->joinTable('cataloginventory_stock_item', 'product_id=entity_id', array('stock_status' => 'is_in_stock'))
            ->addAttributeToSelect('stock_status')
            ->load();

Thursday 23 May 2019

All Customer Groups in Admin system config multiselect

<?php

namespace Namespace\ModuleName\Model\System\Config\Source\Dropdown;

class Frontend implements \Magento\Framework\Option\ArrayInterface {

    protected $_groupCollectionFactory;
    public function __construct(\Magento\Customer\Model\ResourceModel\Group\CollectionFactory $groupCollectionFactory)
    {
        $this->_groupCollectionFactory = $groupCollectionFactory;
    }
   
    public function toOptionArray()
    {
        $this->_options = array();
        if (!$this->_options) {
            $this->_options = $this->_groupCollectionFactory->create()->loadData()->toOptionArray();
        }
        return $this->_options;
    }

}

Tuesday 26 March 2019

Magento shipment view 404 error in admin side

In admin Side Sale->Shipments View 404 error

Solution is edit the below file at line num 49

Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment\View.php


$resultForward->setController('order_shipment')
                ->setModule('adminhtml')    // Change admin to adminhtml    

Thursday 21 February 2019

Add Wyswing editor in Frontend in Magento2.3

Added the Following code in .phtml file

<textarea id="presonal_message"  name="presonal-message"></textarea>

<script>
    require([
    "jquery",
    "mage/translate",
    "mage/adminhtml/events",
    "mage/adminhtml/wysiwyg/tiny_mce/setup"
    ], function(jQuery){
        wysiwygcompany_description = new wysiwygSetup("presonal_message", {
            "width":"99%",  // defined width of editor
            "height":"200px", // height of editor
            "plugins":[{"name":"image"}], // for image
            "tinymce4":{"toolbar":"formatselect | bold italic underline | alignleft aligncenter alignright | bullist numlist | link table charmap","plugins":"advlist autolink lists link charmap media noneditable table contextmenu paste code help table",
            }
        });
        wysiwygcompany_description.setup("exact");
    });
</script>



Wednesday 2 January 2019

Magento 2 Export order,customer and products tables only

Customer Tables Export

mysqldump -u username -p dbname customer_address_entity customer_address_entity_datetime customer_address_entity_decimal customer_address_entity_int customer_address_entity_text customer_address_entity_varchar customer_entity  customer_entity_datetime customer_entity_decimal customer_entity_int customer_entity_text customer_entity_varchar  customer_grid_flat customer_log customer_visitor persistent_session wishlist wishlist_item  wishlist_item_option > hkcustomers31dec.sql


Orders Tables Export


mysqldump -u username -p dbname gift_message quote quote_address quote_address_item quote_id_mask quote_item quote_item_option quote_payment  quote_shipping_rate reporting_orders sales_bestsellers_aggregated_daily sales_bestsellers_aggregated_monthly  sales_bestsellers_aggregated_yearly sales_creditmemo sales_creditmemo_comment sales_creditmemo_grid sales_creditmemo_item sales_invoice sales_invoiced_aggregated sales_invoiced_aggregated_order sales_invoice_comment sales_invoice_grid sales_invoice_item sales_order sales_order_address sales_order_aggregated_created sales_order_aggregated_updated sales_order_grid sales_order_item sales_order_payment sales_order_status_history sales_order_tax sales_order_tax_item sales_payment_transaction sales_refunded_aggregated sales_refunded_aggregated_order sales_shipment sales_shipment_comment sales_shipment_grid sales_shipment_item sales_shipment_track sales_shipping_aggregated sales_shipping_aggregated_order tax_order_aggregated_created  tax_order_aggregated_updated > hkorders31dec.sql

Product Tables List

cataloginventory_stock_item cataloginventory_stock_status cataloginventory_stock_status_idx cataloginventory_stock_status_tmp catalog_category_product catalog_category_product_index catalog_category_product_index_tmp catalog_compare_item catalog_product_bundle_option catalog_product_bundle_option_value catalog_product_bundle_price_index catalog_product_bundle_selection catalog_product_bundle_selection_price catalog_product_bundle_stock_index catalog_product_entity catalog_product_entity_datetime catalog_product_entity_decimal catalog_product_entity_gallery catalog_product_entity_int catalog_product_entity_media_gallery catalog_product_entity_media_gallery_value catalog_product_entity_media_gallery_value_to_entity catalog_product_entity_media_gallery_value_video catalog_product_entity_text catalog_product_entity_tier_price catalog_product_entity_varchar catalog_product_index_eav catalog_product_index_eav_decimal catalog_product_index_eav_decimal_idx catalog_product_index_eav_decimal_tmp catalog_product_index_eav_idx catalog_product_index_eav_tmp catalog_product_index_price catalog_product_index_price_bundle_idx catalog_product_index_price_bundle_opt_idx catalog_product_index_price_bundle_opt_tmp catalog_product_index_price_bundle_sel_idx catalog_product_index_price_bundle_sel_tmp catalog_product_index_price_bundle_tmp catalog_product_index_price_cfg_opt_agr_idx catalog_product_index_price_cfg_opt_agr_tmp catalog_product_index_price_cfg_opt_idx catalog_product_index_price_cfg_opt_tmp catalog_product_index_price_downlod_idx  catalog_product_index_price_downlod_tmp catalog_product_index_price_final_idx catalog_product_index_price_final_tmp catalog_product_index_price_idx catalog_product_index_price_opt_agr_idx catalog_product_index_price_opt_agr_tmp catalog_product_index_price_opt_idx catalog_product_index_price_opt_tmp catalog_product_index_price_tmp catalog_product_index_tier_price catalog_product_index_website catalog_product_link catalog_product_link_attribute_decimal catalog_product_link_attribute_int catalog_product_link_attribute_varchar catalog_product_option catalog_product_option_price catalog_product_option_title catalog_product_option_type_price catalog_product_option_type_title catalog_product_option_type_value catalog_product_relation catalog_product_super_attribute catalog_product_super_attribute_label catalog_product_super_link catalog_product_website catalog_url_rewrite_product_category downloadable_link downloadable_link_price downloadable_link_purchased downloadable_link_purchased_item downloadable_link_title downloadable_sample downloadable_sample_title product_alert_price product_alert_stock report_compared_product_index report_viewed_product_aggregated_daily report_viewed_product_aggregated_monthly report_viewed_product_aggregated_yearly report_viewed_product_index

Friday 2 November 2018

How to remove empty attributes “No” in Magento 2?

 Override the to your theme
 app/code/{Packagename}/{themename}/Magento_Catalog/templates/product/view/attributes.phtml


Just keep line, <?php if($_data['value'] == 'N/A') continue;?> after <?php foreach ($_additional as $_data): ?> line,


 Full code,

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * Product additional attributes template
 *
 * @var $block \Magento\Catalog\Block\Product\View\Attributes
 */
?>
<?php
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $_product = $block->getProduct();
?>
<?php if ($_additional = $block->getAdditionalData()): ?>
    <div class="additional-attributes-wrapper table-wrapper">
        <table class="data table additional-attributes" id="product-attribute-specs-table">
            <caption class="table-caption"><?= /* @escapeNotVerified */ __('More Information') ?></caption>
            <tbody>
            <?php foreach ($_additional as $_data): ?>
<?php if($_data['value'] == 'No') continue;?>
                <tr>
                    <th class="col label" scope="row"><?= $block->escapeHtml(__($_data['label'])) ?></th>
                    <td class="col data" data-th="<?= $block->escapeHtml(__($_data['label'])) ?>"><?= /* @escapeNotVerified */ $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
<?php endif;?>

Thursday 12 July 2018

Msgento Export the all Orders into CSV with Limited Headers

<?php
require_once('app/Mage.php');
    Mage::app();

    $data=Mage::getModel('sales/order')->getCollection();

$fp = fopen('exports_order.csv', 'w+');
//csve headers. You can give your own headers or extra headers
$csvHeader = array('order_id',
    'ship_name',
    'ship_address1',
    'ship_city',
    'ship_state',
    'ship_zip',
    'ship_country',
    'item_id',
    'qty',
    'ship_company',
    'phone_day',
    'email');
fputcsv( $fp, $csvHeader,",");
foreach($data as $row)
{
    //echo "<pre>";Mage::log($row->getData(),null,'orderdata.log');die('here');
    $_order=Mage::getModel('sales/order')->load($row->getId());
    $_shippingAddress = $_order->getShippingAddress();
    //echo "<pre>";Mage::log($_shippingAddress->getData(),null,'shipping.log');die('here');
    foreach ($row->getAllItems() as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getProductId());
 
//echo "<pre>";Mage::log($item->getData(),null,'noworders.log');die();
fputcsv($fp, array($row->getId(),
    $_shippingAddress->getFirstname()." ".$_shippingAddress->getLastname(),
    $_shippingAddress->getStreetFull(),
    $_shippingAddress->getCity(),
    $_shippingAddress->getRegion(),
    $_shippingAddress->getPostcode(),
    $_shippingAddress->getCountry_id(),
    $item->getSku(),
    $item->getQtyOrdered(),
    $_shippingAddress->getCompany(),
    $_shippingAddress->getTelephone(),
    $_shippingAddress->getEmail()
    ) );

    }
 
}
fclose($fp);

Product Collection with out of stock and In Stock in Magento 2

Product collection with out of stock and In stock. use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; $collection = $th...