magento-2-blog
magento-2-blog copied to clipboard
Plugin aroundAddAttributeToSort ArgumentCountError
Preconditions
- Magento: 2.3.5-p1
- PHP: 7.2
- MySQL: 10.2.32-MariaDB-10.2.32
Steps to reproduce
- Install Amasty Product Feed
- Generate any feed with no filter
Expected result
- Correct feed generation
Actual result
- Error occurs:
[Tue Oct 13 19:58:20.280989 2020] [proxy_fcgi:error] [pid 23517] [client xxxxxxxx:44469] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Mageplaza\\Blog\\Plugin\\Catalog\\AttributeSort::aroundAddAttributeToSort(), 3 passed in /var/www/vhosts/xxxxxxx.it/collaudo2.xxxxxxx.it/vendor/magento/framework/Interception/Interceptor.php on line 135 and exactly 4 expected in /var/www/vhosts/xxxxxxx.it/collaudo2.xxxxxxx.it/vendor/mageplaza/magento-2-blog-extension/Plugin/Catalog/AttributeSort.php:58\nStack trace:\n#0 /var/www/vhosts/xxxxxxx.it/collaudo2.xxxxxxx.it/vendor/magento/framework/Interception/Interceptor.php(135): Mageplaza\\Blog\\Plugin\\Catalog\\AttributeSort->aroundAddAttributeToSort(Object(Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection\\Interceptor), Object(Closure), 'position')\n#1 /var/www/vhosts/xxxxxxx.it/collaudo2.xxxxxxx.it/vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection\\Interceptor->Magento\\Framework\\Interception\\{closure}('position')\n#2 /va...', referer: https://collaudo2.xxxxxxx.it/admin/amfeed/feed/edit/id/18/key/ed07fd68df5c2214dad6ae49db50e4ab644884faa91e19b1b076f1e499d62c79/
You can fix it in: Plugin/Catalog/AttributeSort.php
Original (with error)
public function aroundAddAttributeToSort(
Collection $productCollection,
callable $proceed,
$attribute,
$dir
)
Fixed
public function aroundAddAttributeToSort(
Collection $productCollection,
callable $proceed,
$attribute,
$dir = 'ASC'
)
As reference you can check in Magento Core AddAttributeToSort function /vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.php:
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
{
Hi @adri2k, I'm Onesh from Mageplaza. Thanks for your help. We will note it and fix it in the new version.