fresher
fresher

Reputation: 901

restrict some quantity for adding to cart

we needed "pre-order/Back order" feature [ user can buy out-of-stock Products ]

so we wrote custom module. how it works is , if we set value

"yes" to pre order attribute, it will allow for pre-order,

for "NO", it will not show "Pre order" button in view page.

but problem is user can enter any number of quantity & add to cart items.

what we need is what quantity we enter in backend, only it should allow that much quantity to add-to-cart.

<?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">

                <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>

                <?php echo $this->getPriceHtml($_product, true) ?>
                <div class="actions">
                    <?php if($_product->isSaleable()): ?>
                        <?php if($_product->getPreOrder()): ?>
                        <button type="button" title="<?php echo $this->__('Pre-Order') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Pre-Order') ?></span></span></button>

                        <?php endif; ?>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('') ?></span></p>
                    <?php endif; ?>

                </div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    <?php endif; ?>

complete code : http://pasted.co/8c8e0763

Upvotes: 0

Views: 157

Answers (1)

Sunil
Sunil

Reputation: 26

You need to set maximum qty allowed in shopping cart in inventory section when adding products as shown in screen shot.

link

Upvotes: 1

Related Questions