Skip to main content
Avalara Help Center

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

  1. Go to the following file in your storefront code:
    Vendor/ModuleName/view/frontend/templates/cart/form.phtml
  2. Copy the following code as shown in the example:
    <th class="col item" scope="col"><span><?= $block->escapeHtml(__('Use Type')) ?></span></th>
    Example:
    An example for adding Use Type custom code.
  3. Go to the following file:
    Vendor/ModuleName/view/frontend/templates/cart/item/default.phtml
  4. 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:
An example to add Use Type custom code in the Magento storefront.

  • Was this article helpful?