magento-2-blog icon indicating copy to clipboard operation
magento-2-blog copied to clipboard

Plugin aroundAddAttributeToSort ArgumentCountError

Open adri2k opened this issue 4 years ago • 1 comments

Preconditions

  1. Magento: 2.3.5-p1
  2. PHP: 7.2
  3. MySQL: 10.2.32-MariaDB-10.2.32

Steps to reproduce

  1. Install Amasty Product Feed
  2. Generate any feed with no filter

Expected result

  1. Correct feed generation

Actual result

  1. 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)
    {
 

adri2k avatar Oct 13 '20 18:10 adri2k

Hi @adri2k, I'm Onesh from Mageplaza. Thanks for your help. We will note it and fix it in the new version.

phutx avatar Oct 14 '20 02:10 phutx