#StackBounty: #magento-2.1 #sorting #php-7 How to convert Magento 2 Sort By Dropdown to Horizontal List

Bounty: 50

I was trying to Convert Magento 2 Drop down to Horizontal list.

Code Path:

/app/design/frontend/Vendor/Theme/Magento_Catalog/templates/product/list/toolbar/sorter.phtml

Actual Code:

getAvailableOrders() as $_key => $_order): ?> " isOrderCurrent($_key)): ?> selected="selected" > escapeHtml(__($_order)) ?>

What I tried :


Did some research on this and found this LINK

But Couldn’t able to find the Solution. Please help me on this.

Actual Display

Actual Display

Expected Result : On Click Products should sort according to the selection

Expected

Sorter.phtml File

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

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Product list toolbar
 *
 * @var $block MagentoCatalogBlockProductProductListToolbar
 */
use MagentoCatalogModelProductProductListToolbar;
?>
<?php if ($block->getCurrentDirection() == 'desc'): ?> <a title="<?= /* @escapeNotVerified */ __('Set Ascending Direction') ?>" href="#" class="action sorter-action sort-desc" data-role="direction-switcher" data-value="asc"> <span><?= /* @escapeNotVerified */ __('Set Ascending Direction') ?></span> </a> <?php else: ?> <a title="<?= /* @escapeNotVerified */ __('Set Descending Direction') ?>" href="#" class="action sorter-action sort-asc" data-role="direction-switcher" data-value="desc"> <span><?= /* @escapeNotVerified */ __('Set Descending Direction') ?></span> </a> <?php endif; ?> </div>


Get this bounty!!!

#StackBounty: #magento2 #magento-2.1 #database #sales-order Random integrity constraint errors saving orders in Magento 2.1 after payment

Bounty: 50

I have a system that generates quotes, then submits the quotes, which processes a payment. The system is pretty standard: nothing really complicated is going on. The quotes have a single product in them.

After the payment is processed, Magento saves the Order and the payment. However, sometimes we get an exception:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (sales_order_address, CONSTRAINT SALES_ORDER_ADDRESS_PARENT_ID_SALES_ORDER_ENTITY_ID FOREIGN KEY (parent_id) REFERENCES sales_order (entity_id) ON DELETE CASCADE) in /var/www/html/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228

This error suggests to me that it is trying to save the sales_order_address for a non-existent sales_order record, but why would that happen?

The payment was processed successfully on the backend but there is nothing recorded in the database to indicate that. Retrying the same quote again with the same input data usually results in success – the error appears to be transient.

How can I figure out what is causing the sales_order record to be deleted? How is this even possible? I tried searching the Magento code for a transaction rollback that swallows an exception, but didn’t find any. We are using a third-party Stripe payment module but the order-saving part happens after the payment was successfully placed. From what I can see whatever error is happening here is entirely in the core code. The error is happening on the latest (2.1.11) version.


Get this bounty!!!

#StackBounty: #magento-2.1 #database #upgrade #magento2.2.2 Upgrading M2.1.9 to Magento 2.2.2 is very slow

Bounty: 50

We are trying to upgrade a Magento 2.1.9 site to Magento 2.2.2
We have more than 130k products and the process seems to be stuck for more than 3 hours on

Upgrading data..
Module 'Magento_Backend':
Module 'Magento_Catalog':

I used xdebug to profile what process takes so long and apparently problem is:

if (version_compare($context->getVersion(), '2.2.2') < 0) {
            $this->upgradeWebsiteAttributes->upgrade($setup);
        }

Having many products and many attributes the process takes ages. Actually it’s still stuck there so it’s been 3 days. The database size it’s 47GB


Get this bounty!!!

#StackBounty: #magento-2.1 #database #configurable-product #stock #indexing Magento2 – index modes issue

Bounty: 200

We have this Magento 2.1 project running Production mode with “Update on save” mode for all indexes

Our customer manages catalog himself, and reported us some stock issues. Problem was changing quantity for a new product was not working. Process apparently ends fine, regarding the admin message (“Product was saved ok”) but stock was not changed. We look in Magento log files, but we don’t see any related report there

Our solution, finally, was to change indexes to “Update by schedule” and then force a reindex by console command. This solution, as far as I understand, means there is something wrong with that partial reindex fired when saving a product with “Update on save” index mode. What I am asking is for a confirmation about this… should not this problem be reported in Magento log files?

Assuming there is something wrong with our catalog data, I’d like to trace the problem, so I’d like to know which processes (the complete code trace) are fired after a product save in admin, with “Update on save” index mode. In this case, I suppose catalog_inventory ones are the most relevant

Apart from that, and checking the catalog, we’ve noticed some configurable products were sharing simple products, which is rare & we are not sure if could be the origin of the problem (although we assume system wouldn’t let to do that if that’s not allowed). Maybe this could have registered some wrong data in catalog database tables, and causing the problems with partial reindex? If that’s the case… Where can I find in database which data is pending to be processed in the next full reindex process?


Get this bounty!!!

#StackBounty: #magento-2.1 #product #cart #custom-options #image How to set value of an image custom option programmatically Magento 2?

Bounty: 50

I’m trying to set a image Custom Option in a php script before adding the product to cart. Relevant code looks like this:

$specialId = 123;
$customOptions[$specialId] = "Special instruction custom option";

// $imageId = 124;
// $url = 'http://example.com/url/to/image.png';
// $customOptoins[$imageId] = $url;

$params = [
    'product' => $product_id,     //product Id
    'qty'     => $qty,            //quantity of product
    'options' => $customOptions   //custom options
];

$this->_cart->addProduct(
    $_product,
    $params
);

I’m starting with an image url as the code implies. I think I have to use MagentoFrameworkApiDataImageContentInterface, MagentoCatalogModelWebapiProductOptionTypeFileProcessor and maybe curl, but I’m unsure how to proceed.


Get this bounty!!!

#StackBounty: #magento2 #magento-2.1 #orders #edit-order Magento 2: How to edit existing Order without cancel?

Bounty: 50

I am trying to edit Order that includes the below possible cases:

  • Update Order Item Price
  • Increse Order Item Qty Or Cancel Order Item Qty
  • Add New Item into Order

For Adding new Item in Order, I am following the below Way:

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$order = $this->_orderFactory->load('3445');
$order = $objectManager->create('MagentoSalesModelOrder')->load($orderId);

$quote = $objectManager->create('MagentoQuoteModelQuote')->load($order->getQuoteId());

$productId = 4272;
$productQty = 2;

$product = $objectManager->create('MagentoCatalogModelProduct')->load($productId);

//Adding New Item into Quote
$objectManager->create('MagentoQuoteModelQuoteItem')
                ->setProduct($product)
                ->setQuote($quote)
                ->setQty($productQty)
                ->save();

//Quote Address Update
$shippingData = $order->getShippingAddress()->getData();
$quoteAddress = $quote->getShippingAddress();
$shippingData['address_id'] = $quoteAddress->getAddressId();
$quoteAddress->setData($shippingData);
$quoteAddress->save();

$billingData = $order->getBillingAddress()->getData();
$quoteAddress = $quote->getBillingAddress();
$billingData['address_id'] = $quoteAddress->getAddressId();
$quoteAddress->setData($billingData);
$quoteAddress->save();        

//Quote Collect Totals
$quote->getShippingAddress()
        ->setShippingMethod($order->getShippingMethod())
        ->setCollectShippingRates(true);
$quote->setTotalsCollectedFlag(false)->collectTotals();
$quote->save();

then I am planning to add this new Quote Item to convert into Order Item. But using the above code, All Quote Items are deleted and all grand total and subtotal in quote set to 0.

My question is: What is correct way to modify the existing Order ?

Like in sales_order_item table we have the field qty_canceled, Using the below code I can cancel the complete Item ordered qty. But when I am saving the order, Subtotal and Grand total all are set to 0.

$order = $this->_orderFactory->load('3432');
if ($order->canCancel()) {
    $orderItems = $order->getAllItems();        
    foreach ($orderItems as $item) {
        if($item['product_id']==3341) {    

            $item->setQtyCanceled($item['qty_ordered']);
            $item->save();  
        }
    }
    $order->save();
}


Get this bounty!!!

#StackBounty: #magento2 #magento-2.1 #checkout #magento2.2 #knockout Pass data to child template in cart-items of checkout page

Bounty: 100

My site is a market place site where vendors(sellers can sell their product).

Now i want to customize the to group items in cart by each vendor like this:
http://prntscr.com/hmsam6

checkout_index_index.xml

<item name="cart_groups" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/summary/cart-groups</item>
<item name="children" xsi:type="array">
    <item name="cart_items" xsi:type="array">
        <item name="component" xsi:type="string">Magento_Checkout/js/view/summary/cart_groups/cart-items</item>
        <item name="children" xsi:type="array">
            <item name="details" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Checkout/js/view/summary/item/details</item>
                <item name="children" xsi:type="array">
                    <item name="thumbnail" xsi:type="array">
                        <item name="component" xsi:type="string">Magento_Checkout/js/view/summary/item/details/thumbnail</item>
                        <item name="displayArea" xsi:type="string">before_details</item>
                    </item>
                    <item name="subtotal" xsi:type="array">
                        <item name="component" xsi:type="string">Magento_Checkout/js/view/summary/item/details/subtotal</item>
                        <item name="displayArea" xsi:type="string">after_details</item>
                    </item>
                </item>
            </item>
        </item>
    </item>
</item>

cart-group.js

define([
'ko',
'Magento_Checkout/js/model/totals',
'uiComponent',
'Magento_Checkout/js/model/step-navigator',
'Magento_Checkout/js/model/quote'], function (ko, totals, Component, stepNavigator, quote) {
'use strict';

return Component.extend({
    defaults: {
        template: 'Magento_Checkout/summary/cart-groups'
    },
    groups: window.checkoutConfig.quoteItemData,
    getGroups:function(){
        var tempGroups = this.groups;
        var arr = Object.keys(tempGroups).map(function (key) { return tempGroups[key]; });

        return arr;
    },
    /**
     * Returns bool value for items block state (expanded or not)
     *
     * @returns {*|Boolean}
     */
    isItemsBlockExpanded: function () {
        return quote.isVirtual() || stepNavigator.isProcessed('shipping');
    },
    /**
     * Returns cart items qty
     *
     * @returns {Number}
     */
    getItemsQty: function () {
        return parseFloat(this.totals['items_qty']);
    },

    /**
     * Returns count of cart line items
     *
     * @returns {Number}
     */
    getCartLineItemsCount: function () {
        return parseInt(totals.getItems()().length, 10);
    },
});});

cart-group.html

1"/>

</div>

The problem is here:

            <each args="getGroups()">
            <p class="checkout-vendor-shop-name" data-bind="text: vendor_shop_name"></p>
            <!-- ko foreach: $parent.elems() -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!-- /ko -->
        </each>

How can i pass data to child template with each data in this loop: getGroups() array. Right now it is all the data in quote, and it is duplicated 2 times


Get this bounty!!!

#StackBounty: #magento-2.1 #shopping-cart-price-rules #discount #magento-2.2.1 #magento2.2.2 Magento 2 Core Bug Found For Multiple disc…

Bounty: 50

There is core issue in all Magento 2.2.x. When we add two cart price rule with action “Percent of product price discount”. It makes little calculation issue in total discount.

For example, I have created two cart price rule:

Rule 1:

Rule Name: 10% Fix Discount
Coupon: No Coupon
Conditions: Apply for all product
Action: 
    Apply: Percent of product price discount
    Discount Amount: 10

Rule 2:

Rule Name: 5% Fix Discount
Coupon: No Coupon
Conditions: Apply for all product
Action: 
    Apply: Percent of product price discount
    Discount Amount: 5

So the calculation should be like this

For ex. Product Price = $45

First Rule(10% of product price) Discount: (45*10) / 100 = 4.5
Second Rule(5% of product price) Discount: (45*5) / 100 = 2.25

Total Discount = 6.75

But it’s shows $6.53 in total discount.

I have created issue on GitHub and magento team approved the issue. But it’s take some time time to resolve this issue.https://github.com/magento/magento2/issues/12837

Anyone have idea or any patch to resolve this issue?


Get this bounty!!!