Skip to main content

Posts

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

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

Understanding Magento Block and Block Type

For understanding more about magento block types following are some built-in block types which are widely used in layout. core/template : This block renders a template defined by its  template  attribute. The majority of blocks defined in the layout are of type or subtype of  core/template . page/html : This is a subtype of  core/template  and defines the root block. All other blocks are child blocks of this block. page/html_head : Defines the HTML head section of the page which contains elements for including JavaScript, CSS etc. page/html_header : Defines the header part of the page which contains the site logo, top links, etc. page/template_links : This block is used to create a list of links. Links visible in the footer and header area use this block type. core/text_list : Some blocks like  content ,  left ,  right  etc. are of type  core/text_list . When these blocks are rendered, all their child blocks are rendered automa...

Magento Install 2.1.0 errors - Your PHP version is . The required PHP version is .

PHP Version Check Your PHP version is . The required PHP version is .  Download and install PHP from  www.php.net  using this  PHP Documentation . For additional assistance, contact your hosting provider. PHP Settings Check * Your PHP settings are correct. Cannot determine required PHP extensions: Warning: is_dir(): open_basedir restriction in effect. File(/etc/pki/tls/certs) is not within the allowed path(s): /tmp:/var/tmp:/usr/local/lib/php/ :/usr/local/php56/lib/php/) in /public_html/ve ndor/composer/composer/src/Composer/Util/RemoteFil esystem.php on line 914 It was SSL reason. In Magento 2.1.0 in default uses ssl. I'm not using ssl and the error arises. I just edit the config section of composer.json file in the root of magento and added the following line and every thing is OK. "disable-tls" : true

Magento2 get product data by loading product id in root directory

 Create  test.php  in magento root directory <?php echo '<pre>'; require __DIR__ . '/app/bootstrap.php'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); /** @var \Magento\Framework\App\Http $app */ $obj = $bootstrap->getObjectManager(); $state = $obj->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); /** @var \Magento\Framework\App\Http $app */ $app = $bootstrap->createApplication('TestApp'); $bootstrap->run($app); And next create TestApp.php <?php class TestApp extends \Magento\Framework\App\Http implements \Magento\Framework\AppInterface {  public function launch() {        echo '<pre>';         $objectManager = \Magento\Framework\App\ObjectManager::getInstance();         $product = $objectManager->get('Magento\Catalog\Model\Product')->load(2047);         var_dump($pr...

5 worst Magento practices

I hope this article will help many to save their eCommerce problem and to optimize their code. Magento is a wonderful platform to kick start your e-commerce endeavors. But the worst part is its development flow. I will introduce you the 5 worst Magento development practices followed by detailed example. 1.  Collections – query results limitation To improve code performance and scalability remember to apply limitation on the collection’s query results — it’s much better to do  $collection->getSize()  instead of  $collection->count()  or  count($collection)  because that ways, all of the items will be loaded from the database and than iterated. 2.  SQL queries inside a loop Bad practice is to load Magento models inside a loop. Running SQL query is very expensive operation and doing it in a loop tends to make it even worse. Instead of doing that we could use data collections to load models and then process it.  To be careful when ...