magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.5k stars 9.31k forks source link

Code optimization for the offline shipping methods. #23143

Closed atwixfirster closed 5 years ago

atwixfirster commented 5 years ago

Summary (*)

Flat Rate, Free Shipping, and Store Pickup shipping methods use protected $_code variable to provide information about carrier's code.

For example, Flat Rate shipping method:

class Flatrate extends AbstractCarrier implements CarrierInterface
{
    /**
     * @var string
     */
    protected $_code = 'flatrate';

...

In the getAllowedMethods() function for this shipping method we have:

 * @return array
     */
    public function getAllowedMethods()
    {
        return ['flatrate' => $this->getConfigData('name')];
    }

So, carrier's code is duplicated.

Examples (*)

Proposed solution

Use $this->_code in the getAllowedMethods() function of Flat Rate, Free Shipping, and Store Pickup.

For example, a code optimization for Flat Rate will look like:

/**
     * @return array
     */
    public function getAllowedMethods()
    {
        return [$this->_code => $this->getConfigData('name')];
    }
m2-assistant[bot] commented 5 years ago

Hi @atwixfirster. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@atwixfirster do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?


m2-assistant[bot] commented 5 years ago

Hi @atwixfirster. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:


orlangur commented 5 years ago

@atwixfirster such improvements may be proposed directly as pull requests without even reporting an issue ;) Issues are mostly useful when we deal with a bug and need to verify it against all release lines.

atwixfirster commented 5 years ago

@atwixfirster such improvements may be proposed directly as pull requests without even reporting an issue ;) Issues are mostly useful when we deal with a bug and need to verify it against all release lines.

Thanks for the flow explanation, @orlangur ! I will use it in my future PRs.

👍

magento-engcom-team commented 5 years ago

Hi @atwixfirster. Thank you for your report. The issue has been fixed in magento/magento2#23144 by @atwixfirster in 2.3-develop branch Related commit(s):

The fix will be available with the upcoming 2.3.4 release.