Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

https://github.com/magesuite/business-checkout

This module adds an additional field in the checkout with customer type, which can be private or business. for business customers additional fields: company and Vat ID are shown.

Table of Contents

Installation

Info

This module is optional

Code Block
composer require "creativestyle/magesuite-business-checkout" ^1.0.0

Admin settings

In order to enable business checkout set Stores -> Configuration ->MageSuite -> Business Checkout

is enabled to Yes

Backend

Note

TODO - BE documentation and review of documentation is needed

Adding an additional dropdown field with content type to the form

vendor/creativestyle/magesuite-business-checkout/Processor/Layout/CustomerTypeField.php:29
Code Block
breakoutModefull-width
class CustomerTypeField extends \Magento\Checkout\Model\Layout\AbstractTotalsProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcessorInterface
{
    public function process($jsLayout)
    {
        if(!$this->configuration->isEnabled()){
            return $jsLayout;
        }

        $customField = $this->getExtensionAttributeFieldAsArray();

        $newJsLayout = [
            'components' => [
                'checkout' => [
                    'children' => [
                        'steps' => [
                            'children' => [
                                'shipping-step' => [
                                    'children' => [
                                        'shippingAddress' => [
                                            'children' => [
                                                'shipping-address-fieldset' => [
                                                    'children' => [
                                                        \MageSuite\BusinessCheckout\Helper\Configuration::CUSTOMER_TYPE_ATTRIBUTE => $customField
                                                    ]
                                                ]
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ];

        $jsLayout = array_merge_recursive($jsLayout, $newJsLayout);
        return $jsLayout;
    }
}

vendor/creativestyle/magesuite-business-checkout/Model/Entity/Attribute/Source/CustomerType.php:10
Code Block
class CustomerType extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
{
    public function getAllOptions()
    {
        if ($this->_options === null) {
            $this->_options = [
                ['value' => self::PRIVATE, 'label' => __('Private')],
                ['value' => self::BUSINESS, 'label' => __('Business')]
            ];
        }
        return $this->_options;
    }
}

Saving address form

vendor/creativestyle/magesuite-business-checkout/Plugin/Checkout/Model/ShippingInformationManagement/SaveCustomerTypeInQuote.php:16
Code Block
class SaveCustomerTypeInQuote
{
public function beforeSaveAddressInformation(
        \Magento\Checkout\Model\ShippingInformationManagement $subject,
        $cartId,
        \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
    )
    {
        $shippingAddress = $addressInformation->getShippingAddress();
        .....
        $customerType = $shippingAddress->getExtensionAttributes()->getCustomerType();
        .....
        $quote = $this->quoteRepository->getActive($cartId);
        $quote->setCustomerType($customerType);

        return [$cartId, $addressInformation];
    }
}

Frontend

With business checkout there is an additional dropdown field in the forms:

It allows one to choose between private and business customer types:

There are business type-only fields: Company and VAT ID. They are shown when the business customer type is chosen and hidden when the private customer type is selected.

Company and VAT ID must be enabled in the admin panel (Stores -> Configuration -> Customers > Customer Configuration -> Name and Address Options) and Show VAT Number on Storefront ste to yes (in Show VAT Number on Storefront tab)

Customer Type is saved along with the address.

Image Modified