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);

Create Shipment for Order Using Script

<?php
$orderid = 1;
$order = Mage::getModel('sales/order')->load($orderid );
$shipmentItems = array();
foreach ($order->getAllItems() as $item) {
$shipmentItems [$item->getId()] = $item->getQtyToShip();
}

// Prepear shipment and save ....
if ($order->getId() && !empty($shipmentItems) && $order->canShip()) {
    $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($shipmentItems);
    $shipment->save();
}
$shipment_collection = Mage::getResourceModel('sales/order_shipment_collection');
$shipment_collection->addAttributeToFilter('order_id', $data[0]);
foreach($shipment_collection as $sc) {
    $shipment = Mage::getModel('sales/order_shipment');
    $shipment->load($sc->getId());
    if($shipment->getId() != '') {
$track = Mage::getModel('sales/order_shipment_track')
->setShipment($shipment)
->setData('title', $data[5])
->setData('number', $data[6])
->setData('order_id', $shipment->getData('order_id'))
->save();
    }
}
?>

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...