Skip to main content

Posts

Showing posts from April, 2017

Magento 2: How to truncate customers, products, reviews and orders table

NOTE ::  Please take database backup prior to executing these queries. SET FOREIGN_KEY_CHECKS=0; Truncate order tables # Clean order history TRUNCATE TABLE `sales_bestsellers_aggregated_daily`; TRUNCATE TABLE `sales_bestsellers_aggregated_monthly`; TRUNCATE TABLE `sales_bestsellers_aggregated_yearly`; # Clean order infos TRUNCATE TABLE `sales_creditmemo`; TRUNCATE TABLE `sales_creditmemo_comment`; TRUNCATE TABLE `sales_creditmemo_grid`; TRUNCATE TABLE `sales_creditmemo_item`; TRUNCATE TABLE `sales_invoice`; TRUNCATE TABLE `sales_invoiced_aggregated`; TRUNCATE TABLE `sales_invoiced_aggregated_order`; TRUNCATE TABLE `sales_invoice_comment`; TRUNCATE TABLE `sales_invoice_grid`; TRUNCATE TABLE `sales_invoice_item`; TRUNCATE TABLE `sales_order`; TRUNCATE TABLE `sales_order_address`; TRUNCATE TABLE `sales_order_aggregated_created`; TRUNCATE TABLE `sales_order_aggregated_updated`; TRUNCATE TABLE `sales_order_grid`; TRUNCATE TABLE `sales_

How to create shipment programmatically in magento2

if we need to programmatically create shipment for an order then you can create by following way. // Load the order $order = $this->_objectManager->create('Magento\Sales\Model\Order') ->loadByAttribute('increment_id', '302372359'); OR $order = $this->_objectManager->create('Magento\Sales\Model\Order') ->load('1079'); // Check if order can be shipped or has already shipped if (! $order->canShip()) { throw new \Magento\Framework\Exception\LocalizedException( __('You can\'t create an shipment.') ); } // Initialize the order shipment object $convertOrder = $this->_objectManager->create('Magento\Sales\Model\Convert\Order'); $shipment = $convertOrder->toShipment($order); // Loop through order items foreach ($order->getAllItems() AS $orderItem) { // Check if order item has qty to ship or is virtual if (! $orderItem->getQtyToShip() || $o