I am working on a project where, on the product page, instead of the usual custom settings, there are some custom settings, and then a database is queried to find out if certain vendors carry the product. It then displays the list of providers through javascript, as shown below.

I want the cart add block to be displayed next to EVERY seller. Since all this was dynamically created, I had to pass the provider ID to the “add to cart” script that I created. I took the original application / design / frontend / base / default / template / catalog / product / view / addtocart.phtml and made my own as shown below. The following php file is called via ajax. There were many $ this variables in the addtocart.phtml source file. I need to simulate $ this (no matter what model the helper link is), so this block works. I am without much success. Can someone see what I'm doing wrong or what can I do differently? Many thanks!
<?php
require_once('/var/www/Staging/public_html/app/Mage.php');
umask(0);
Mage::app();
if($_POST && is_numeric($_POST['value'])){
$value = $_POST['value'];
}
if($_POST && is_numeric($_POST['product_id'])){
$product_id = $_POST['product_id'];
}
$helper = Mage::helper('core');
$block = new Mage_Catalog_Blockproduct_View();
$product = Mage::getModel('catalog/product')->load($product_id);
$buttonTitle = '';
?>
<div class="add-to-cart">
<label for="qty"><?php echo $helper->__('Qty:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $block->getProductDefaultQty($product) * 1 ?>" title="<?php echo $helper->__('Qty') ?>" class="input-text qty" />
<button onclick="window.location = '<?php echo Mage::helper('checkout/cart')->getAddUrl($product);?>'" type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" id='$value'><span><?php echo $buttonTitle ?></span></button>
</div>
source
share