Add Use Type custom code in Magento storefront
This article applies to:AvaTax
The Use Type field in the Magento storefront is optional and not part of the standard connector installation. It is provided separately as a custom code. You can add the custom code to your custom store theme.
Steps
- Go to the following file in your storefront code:
Vendor/ModuleName/view/frontend/templates/cart/form.phtml
- Copy the following code as shown in the example:
<th class="col item" scope="col"><span><?= $block->escapeHtml(__('Use Type')) ?></span></th>
Example:
- Go to the following file:
Vendor/ModuleName/view/frontend/templates/cart/item/default.phtml
- Insert the following code as shown in the example:
<td class="col msrp" data-th="<?= $block->escapeHtml(__('Use Type')) ?>"> <?php $blockAbstractCartObj= $block->getLayout()->createBlock('Avalara\BrSalesTax\Block\Cart\AbstractCart'); $companyUseType = $blockAbstractCartObj->getCustomerCompanyUseType(); $options = $constantHelper->getUseTypeValues(); ?> <select name="cart[<?php echo $_item->getId() ?>][use_type]" id="cart_use_type_<?php echo $_item->getId() ?>" title="<?= $block->escapeHtmlAttr(__('Use Type')) ?>" > <?php $selectedAvaUseType = ''; if( $_item->getUseType() && !empty($_item->getUseType()) ) { $selectedAvaUseType = $_item->getUseType(); }else if( $companyUseType && !empty($companyUseType) ) { $selectedAvaUseType = $companyUseType; } ?> <?php foreach ($options as $codes): ?> <?php $selected = ''; if ( $selectedAvaUseType == $codes['value'] ) { $selected = 'selected="selected"'; } ?> <option <?php echo $selected; ?> value="<?= $block->escapeHtmlAttr($codes['value']) ?>" > <?= $block->escapeHtml($codes['label']) ?> </option> <?php endforeach; ?> </select> </td>
Example:
See also
Set up or change Use Type from the Magento storefront
Change the default Use Type in the shopping cart