Tweeted twitter.com/#!/StackMagento/status/327377033292300288
2 code edit
source | link

I am working on a project where on the product page instead of the normal configurable options, there are some configurable options and then the database is queried to see if particular vendors carry the product. It then displays the list of vendors via javascript as shown below.

enter image description here

I want the add to cart block to show up next to EACH vendor. Because this is all dynamically created, I had to pass the vendor ID to an "add to cart" script that I created. I took the original app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml and made my own as seen below. The following php file is called via ajax. The original addtocart.phtml had a bunch of $this variables. I need to simulate $this (whatever model, helper its referring to) so that this block works. I am without much success. Can someone see what I am doing wrong or what I could do differently? Thanks so much!

<?php $value = $_POST['value'];?>
 <?php
require_once require_once('/var/www/Staging/public_html/app/Mage.php';php'); ?>
<?php umask(0);
  Mage::app();
 ?>
//$product =<?php Mage::getModel('catalog/product')->load($id);
print_r($product$value = Mage::registry('current_product'));
$_POST['value'];?>

<?php $_product$block = Mage::registrygetModel('current_product''catalog/product'); ?>
<?php $buttonTitle$_product = Mage::registry('current_product')->getId()->__('Add to Cart'); 
//Mage::registry('current_product')->__('Add to Cart'); ?>
    <?php //if($_product->isSaleable()): ?>
        <div class="add-to-cart">
        <?php //if(!$_product->isGrouped()): ?>
            <label for="qty"><?php echo Mage::registry('current_product')$block->__('Qty:') ?></label>
            <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo Mage::registry('current_product')$block->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::registry('current_product')$block->__('Qty') ?>" class="input-text qty" />
        <?php //endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" id='$value'><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo Mage::registry('current_product')$block->getChildHtml('', true, true) ?>
            </div>
    <?php //endif; ?>

I am working on a project where on the product page instead of the normal configurable options, there are some configurable options and then the database is queried to see if particular vendors carry the product. It then displays the list of vendors via javascript as shown below.

enter image description here

I want the add to cart block to show up next to EACH vendor. Because this is all dynamically created, I had to pass the vendor ID to an "add to cart" script that I created. I took the original app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml and made my own as seen below. The following php file is called via ajax. The original addtocart.phtml had a bunch of $this variables. I need to simulate $this (whatever model, helper its referring to) so that this block works. I am without much success. Can someone see what I am doing wrong or what I could do differently? Thanks so much!

<?php $value = $_POST['value'];?>
<?php
require_once '/var/www/Staging/public_html/app/Mage.php';
umask(0);
 Mage::app();
 
//$product = Mage::getModel('catalog/product')->load($id);
print_r($product = Mage::registry('current_product'));
?>

<?php $_product = Mage::registry('current_product'); ?>
<?php $buttonTitle = Mage::registry('current_product')->getId()->__('Add to Cart'); 
//Mage::registry('current_product')->__('Add to Cart'); ?>
    <?php if($_product->isSaleable()): ?>
        <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
            <label for="qty"><?php echo Mage::registry('current_product')->__('Qty:') ?></label>
            <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo Mage::registry('current_product')->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::registry('current_product')->__('Qty') ?>" class="input-text qty" />
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" id='$value'><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo Mage::registry('current_product')->getChildHtml('', true, true) ?>
            </div>
    <?php endif; ?>

I am working on a project where on the product page instead of the normal configurable options, there are some configurable options and then the database is queried to see if particular vendors carry the product. It then displays the list of vendors via javascript as shown below.

enter image description here

I want the add to cart block to show up next to EACH vendor. Because this is all dynamically created, I had to pass the vendor ID to an "add to cart" script that I created. I took the original app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml and made my own as seen below. The following php file is called via ajax. The original addtocart.phtml had a bunch of $this variables. I need to simulate $this (whatever model, helper its referring to) so that this block works. I am without much success. Can someone see what I am doing wrong or what I could do differently? Thanks so much!

    <?php require_once('/var/www/Staging/public_html/app/Mage.php'); ?>
<?php umask(0); Mage::app();?>
<?php $value = $_POST['value'];?>

<?php $block = Mage::getModel('catalog/product');?>
<?php $_product =  Mage::registry('current_product'); ?>
<?php //if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php //if(!$_product->isGrouped()): ?>
        <label for="qty"><?php echo $block->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $block->getProductDefaultQty() * 1 ?>" title="<?php echo $block->__('Qty') ?>" class="input-text qty" />
        <?php //endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" id='$value'><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo $block->getChildHtml('', true, true) ?>
        </div>
    <?php //endif; ?>
1
source | link

Dynamically create add to cart block for each final configurable option, Helper for $this

I am working on a project where on the product page instead of the normal configurable options, there are some configurable options and then the database is queried to see if particular vendors carry the product. It then displays the list of vendors via javascript as shown below.

enter image description here

I want the add to cart block to show up next to EACH vendor. Because this is all dynamically created, I had to pass the vendor ID to an "add to cart" script that I created. I took the original app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml and made my own as seen below. The following php file is called via ajax. The original addtocart.phtml had a bunch of $this variables. I need to simulate $this (whatever model, helper its referring to) so that this block works. I am without much success. Can someone see what I am doing wrong or what I could do differently? Thanks so much!

<?php $value = $_POST['value'];?>
<?php
require_once '/var/www/Staging/public_html/app/Mage.php';
umask(0);
Mage::app();

//$product = Mage::getModel('catalog/product')->load($id);
print_r($product = Mage::registry('current_product'));
?>

<?php $_product = Mage::registry('current_product'); ?>
<?php $buttonTitle = Mage::registry('current_product')->getId()->__('Add to Cart'); 
//Mage::registry('current_product')->__('Add to Cart'); ?>
    <?php if($_product->isSaleable()): ?>
        <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
            <label for="qty"><?php echo Mage::registry('current_product')->__('Qty:') ?></label>
            <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo Mage::registry('current_product')->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::registry('current_product')->__('Qty') ?>" class="input-text qty" />
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" id='$value'><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo Mage::registry('current_product')->getChildHtml('', true, true) ?>
            </div>
    <?php endif; ?>