Skip to content

Pagescreen complaints for default_cart.php #253

@lushdomain

Description

@lushdomain

pagespeed also complains that the default_cart.php file is not accessible friendly.

I changed the original file from this:

<?php
/**
 * @package J2Store
 * @copyright Copyright (c)2014-17 Ramesh Elamathi / J2Store.org
 * @license GNU GPL v3 or later
 */

// No direct access
defined('_JEXEC') or die;

if(!empty($this->product->addtocart_text)) {
	$cart_text = JText::_($this->product->addtocart_text);
} else {
	$cart_text = JText::_('J2STORE_ADD_TO_CART');
}

$show = J2Store::product ()->validateVariableProduct($this->product);
?>
	<?php echo J2Store::plugin()->eventWithHtml('BeforeAddToCartButton', array($this->product, J2Store::utilities()->getContext('default_cart'))); ?>
	<?php if($show): ?>
		<div class="cart-action-complete" style="display:none;">
				<p class="text-success">
					<?php echo JText::_('J2STORE_ITEM_ADDED_TO_CART');?>
					<a href="<?php echo $this->product->checkout_link; ?>" class="j2store-checkout-link">
						<?php echo JText::_('J2STORE_CHECKOUT'); ?>
					</a>
				</p>
		</div>


		<div id="add-to-cart-<?php echo $this->product->j2store_product_id; ?>" class="1j2store-add-to-cart">

		<?php echo J2Store::product()->displayQuantity('com_j2store.productlist.bootstrap3', $this->product, $this->params, array( 'class'=>'input-mini form-control ' ) ); ?>

			<input type="hidden" name="product_id" value="<?php echo $this->product->j2store_product_id; ?>" />

				<input
					data-cart-action-always="<?php echo JText::_('J2STORE_ADDING_TO_CART'); ?>"
					data-cart-action-done="<?php echo $cart_text; ?>"
					data-cart-action-timeout="1000"
				   value="<?php echo $cart_text; ?>"
				   type="submit"
				   class="j2store-cart-button <?php echo $this->params->get('addtocart_button_class', 'btn btn-primary');?>"
				   />

	   </div>
	<?php else: ?>
			<input value="<?php echo JText::_('J2STORE_OUT_OF_STOCK'); ?>" type="button" class="j2store_button_no_stock btn btn-warning" />
	<?php endif; ?>

	<?php echo J2Store::plugin()->eventWithHtml('AfterAddToCartButton', array($this->product, J2Store::utilities()->getContext('default_cart'))); ?>

	<input type="hidden" name="option" value="com_j2store" />
	<input type="hidden" name="view" value="carts" />
	<input type="hidden" name="task" value="addItem" />
	<input type="hidden" name="ajax" value="0" />
	<?php echo JHTML::_( 'form.token' ); ?>
	<input type="hidden" name="return" value="<?php echo base64_encode( JUri::getInstance()->toString() ); ?>" />
	<div class="j2store-notifications"></div>

to this:

<?php
/**
 * @package J2Store
 * @copyright Copyright (c)2014-17 Ramesh Elamathi / J2Store.org
 * @license GNU GPL v3 or later
 */
// No direct access
defined('_JEXEC') or die;
if(!empty($this->product->addtocart_text)) {
	$cart_text = JText::_($this->product->addtocart_text);
} else {
	$cart_text = JText::_('J2STORE_ADD_TO_CART');
}
$show = J2Store::product ()->validateVariableProduct($this->product);
?>
	<?php echo J2Store::plugin()->eventWithHtml('BeforeAddToCartButton', array($this->product, J2Store::utilities()->getContext('default_cart'))); ?>
	<?php if($show): ?>
		<div class="cart-action-complete" style="display:none;">
				<p class="text-success">
					<?php echo JText::_('J2STORE_ITEM_ADDED_TO_CART');?>
					<a href="<?php echo $this->product->checkout_link; ?>" class="j2store-checkout-link">
						<?php echo JText::_('J2STORE_CHECKOUT'); ?>
					</a>
				</p>
		</div>
		<div id="add-to-cart-<?php echo $this->product->j2store_product_id; ?>" class="j2store-add-to-cart">
		<?php echo J2Store::product()->displayQuantity('com_j2store.productlist.bootstrap3', $this->product, $this->params, array( 'class'=>'input-mini form-control ' ) ); ?>
			<input type="hidden" name="product_id" value="<?php echo $this->product->j2store_product_id; ?>" />
				<input
					data-cart-action-always="<?php echo JText::_('J2STORE_ADDING_TO_CART'); ?>"
					data-cart-action-done="<?php echo $cart_text; ?>"
					data-cart-action-timeout="1000"
				   value="<?php echo $cart_text; ?>"
				   type="submit"
				   class="j2store-cart-button <?php echo $this->params->get('addtocart_button_class', 'btn btn-primary');?>"
				   />
	   </div>
	   <script>
	   (function() {
	       var qtyInput = document.querySelector('#add-to-cart-<?php echo $this->product->j2store_product_id; ?> input[type="number"][name="product_qty"]');
	       if (qtyInput && !qtyInput.hasAttribute('aria-label')) {
	           qtyInput.setAttribute('aria-label', 'Quantity');
	       }
	   })();
	   </script>
	<?php else: ?>
			<input value="<?php echo JText::_('J2STORE_OUT_OF_STOCK'); ?>" type="button" class="j2store_button_no_stock btn btn-warning" />
	<?php endif; ?>
	<?php echo J2Store::plugin()->eventWithHtml('AfterAddToCartButton', array($this->product, J2Store::utilities()->getContext('default_cart'))); ?>
	<input type="hidden" name="option" value="com_j2store" />
	<input type="hidden" name="view" value="carts" />
	<input type="hidden" name="task" value="addItem" />
	<input type="hidden" name="ajax" value="0" />
	<?php echo JHTML::_( 'form.token' ); ?>
	<input type="hidden" name="return" value="<?php echo base64_encode( JUri::getInstance()->toString() ); ?>" />
	<div class="j2store-notifications"></div>

It solves the warning:

Form elements do not have associated labels
Labels ensure that form controls are announced properly by assistive technologies, like screen readers. Learn more about form element labels.
Failing Elements

div.row > div.col-md-9 > form#productFilters > input.j2store-product-search-input
<input type="text" name="search" value="" class="j2store-product-search-input">
form#j2store-addtocart-form-365 > div#add-to-cart-365 > div.product-qty > input.input-mini
<input type="number" name="product_qty" value="1" class="input-mini form-control " min="0" step="1">
form#j2store-addtocart-form-364 > div#add-to-cart-364 > div.product-qty > input.input-mini
<input type="number" name="product_qty" value="1" class="input-mini form-control " min="0" step="1">  etc....

But, I'm sure there will be a better solution than adding the additional aria by JS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions