Magento 2 Getting an error "The requested qty exceeds the maximum qty allowed in shopping cart." - magento2

code example:
class CustomAddToCart {
public function __construct(
\Magento\Checkout\Model\Cart $cart
) {
$this->cart = $cart;
}
public function execute()
{
$product = ....
$this->cart->addProduct($product, ['product' => $product->getId(), 'qty' => 1]);
$this->cart->save();
}
}
When the cart do the save Magento tries to change the quantity of the last item currently in the cart into 2. Since all products in our website only have a stock quantity of 1 it can only be added in the cart once. So I do not know why Magento is doing this. Can anybody please help me if someone already had experience this.
xdebug break point where last item in cart is increased from 1 to 2
xdebug call stack trace of the trace

I hope you are doing great!
Please check below configuration which is global for all the products.
1. Stores > Configuration > Catalog > Inventory > Product Stock Options > Maximum Qty Allowed in Shopping Cart
Secondly, you need to check the below configuration of the product for which the quantity is changing. This setting will take the precedence on global setting so please do the product related changes with the help of below setting and try one more time.
2. Catalog > Products > Edit the product which is having a problem while adding to the cart > Search for "Advanced Inventory" and click on it you will get Maximum Qty Allowed in Shopping Cart and change it to 1 (It can be anything)
3. Don't forget to clear the cache.
Please take a look at the below link.
https://github.com/magento/magento2/issues/18477
Thanks,
Sonu

Related

product not showing on cateogry page after migration from Magento 2.2.4 to Magento 2.4.0

I have updated Magento 2.2.4 to Magento 2.4.0. After that products are not showing on category page. please note when i search products were showing and also product details page is opening.
Please see the screenshot:
I have tried indexing , creating inventory view, tried creating new product and category, stock is also fine, product also assigned to website. Elastic search also configured as required .
I also tried to print to print the collection query on ListProduct.php
and I get this
"SELECT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, IFNULL(review_summary.reviews_count, 0) AS `reviews_count`, IFNULL(review_summary.rating_summary, 0) AS `rating_summary`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.customer_group_id = 0 AND price_index.website_id = '1' LEFT JOIN `review_entity_summary` AS `review_summary` ON e.entity_id = review_summary.entity_pk_value AND review_summary.store_id = 1 AND review_summary.entity_type = (SELECT `review_entity`.`entity_id` FROM `review_entity` WHERE (entity_code = 'product')) INNER JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id WHERE (NULL)"
I had the same problem you described, tried the same steps you outlined, tracked down the same collection query. Ultimately the cause was a product attribute added by a third-party extension, said attribute was improperly configured.
Try the resolution explained here — https://magento.stackexchange.com/a/322623/36384

How to Remove zero amount line fom axapta form by code

When we are processing EOS(end of service) of an employee then system automatically generate the zero line 0.00 as Encashment quantity for rendom employee somehow.My client don't want this zero line in this form becuase when they are trying to post EOS to general ledger its showing the error as amount can't be post without value.So how to code in x++ to remove the zero amount line from my EOS form if there is any 0.00 encashment amount.
enter image description here
In Above screenshot system has calculated the encashment quantity as zero so when we processed EOS. Kindly requesting give some suggestions to handle this scenario by X++ code.
If you are using a datasource to get the value then there is a property called "Insert if empty" on the datasource (In this case the datasource with the EncashmentQuantity field) which is automatically set as "yes" but you can change it to "no" and the value should not be shown if it is 0. I am not sure this is what you are talking about but it might be.
I hope to understood the question.
"My client don't want this zero line in this form becuase...."
I think you have this way, If you want to filter the record without 0 Value by code, you can use filter in DataSource rightClick override executequery method and insert code looklike follow:
public void executeQuery()
{
this.query().dataSourceTable(tableNum(**YourTablename**)).addRange(fieldNum(**YourTableName**,**YoutFilterField**)).value(strFmt("%1", '>0'));
super();
}
ForExample :
this.query().dataSourceTable(tableNum(LedgerJournalTrans)).addRange(fieldNum(LedgerJournalTrans,AmountCurCredit)).value(strFmt("%1", '>0')); // DISCARD all record lower than 0
or
this.query().dataSourceTable(tableNum(LedgerJournalTrans)).addRange(fieldNum(LedgerJournalTrans,AmountCurCredit)).value(SysQuery::valueNot(0));
I share this useful links :
Expressions in query ranges
SimilarQuestion
StandardGuide
Good work!

Slightly tweak paypal user interface

Perhaps a stupid question but I have to ask... Im targeting users in a country where PayPal does not support their (the country's) currency type as a billing amount so I changed PayPal payment.php page (is this allowed...?) like so:
//' TODO: Enter the total Payment Amount within the quotes.
//' example : $paymentAmount = "15.00";
//'------------------------------------
$usd_rate = "13.50"; //I might still add a funtion to get live exchange rate here
$zar = "50.00";
$amount = $zar / $usd_rate;
$amount = round($amount,2);
$paymentAmount = $amount;
The following is working and I am getting this:
What I want to do
Can you see the empty / blank circle on the left...? I would like to add the variable value $zar in that circle so it will read something like:
1st circle (left)
$50.00ZAR =
2nd circle (right)
$3.70 USD
PayPal does not support this tweak, unfortunately.
But you may want to try putting it in the item information to display on PayPal. The way to put it there depends on the product you use. PayPal docs will provide the info.
https://developer.paypal.com

Obtain credits for a specific day

I can use the following to obtain a list of all my credits
<?php
$marketplace = Balanced\Marketplace::mine();
$credits = $marketplace->credits->query()->all();
?>
I can modify this to obtain the credits for a specific customer
$credits = $customer->credits->query()->all();
Note the chance is from querying $marketplace to querying $customer.
Can I modify all() or by other means obtain credits with different parameters.
e.g. Credits in the last 24 hour or for a specific day,...
I know I can get the entire list of credits and then search though it but it seems resource hungry to get everything if only a sub-section is required.
I believe you can filter like this
$customer->credits->query()->filter(
Credit::$f->created_at->lt($before),
Credit::$f->created_at->gte($after),
)->all();
Here's another example on the internet that shows how to filter via the meta field too - https://gist.github.com/mjallday/5166040

The name of the custom list for "Detected in Cycle" field in QC

I am tring to extract the possible values available in QC defects section for "Detected in Cycle" field.
I tried doing it for "Defects status", i was able to extract the values Resolved, Open, Assigned....
The code which i tried for extracting status values is as below:
Set cust = QCConnection.customization
Set custlists = cust.Lists
Set custlist = cutslists.List
Set custlist = custlists.List("Bug Status") 'it is listing complete bug status values not specific 'to the project
Set listrootnode = custlist.RootNode
Set listchildren = listrootnode.Children
For Each listname In listchildren
MsgBox (listname.Name) 'Assigned, deferred, cancel...... all are displayed
Next
But here i need to replace Bug_status with something related to Detected in cycle field. So i need help in finding out this name of custom list....
i was able to get list of cycles avaiable in QC project. Here is the code:
Set cycles = UserForm9.QCConnection.CycleFactory ' here CycleFactory, a method in QC API will help ' you get complete list
So Bug status is a customization list.
And Cycles is not customized list but could be extracted by CycleFacotry method.