Versions Compared

Key

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

...

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

...

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:

...

Customer Type is saved along with the address.

...

Note

TODO - BE documentation and review of documentation is needed