Let's get to the root of what you're asking:
I need to simulate $this (whatever model, helper its referring to) so
that this block works. I am without much success.
The addtocart.phtml view is called via this xml declaration in app/design/frontend/base/default/layout/catalog.xml:
<block type="catalog/product_view" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml"/>
That means that the $this
you're referring to is the model catalog/product_view
. Assuming no rewrites, that should translate to the class file Mage_Catalog_Block_Product_View
, found in app/code/core/Mage/Catalog/Block/Product/View.php.
So, with all of that aside, you want $this
to behave as if it's being called from the block. Assuming you're still using your standalone script called via AJAX, you should replace $this
with $block
- loading that as a new instance of the block model referenced above. This may lead to undesired effects - for instance - $block->getProduct()
won't work.
Edited standalone addtocart.phtml:
Based on your edit, I have updated this answer:
<?php
require_once('/var/www/Staging/public_html/app/Mage.php');
umask(0);
Mage::app();
//ensure that the value is legitimate
if($_POST && is_numeric($_POST['value'])){
$value = $_POST['value'];
}
//pass this in your ajax call for the add button
if($_POST && is_numeric($_POST['product_id'])){
$product_id = $_POST['product_id'];
}
$helper = Mage::helper('core'); //for translation
$block = new Mage_Catalog_Block_Product_View(); // not best practice, but neither are standalones
$product = Mage::getModel('catalog/product')->load($product_id); // no need to use the _ here, it's not protected/private; additonally Mage::registry won't work because you're technically not on a product detail page
$buttonTitle = ''; //you are using this, but it isn't set
?>
<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>
Some other thoughts:
You're using $_GET['value']
- don't accept unfiltered input from users. You're placing this directly into the add to cart button. Anyone could munge this to inject scripts and other bad stuff onto a page via the URL. This is called XSS - read more here: http://phpmaster.com/php-security-cross-site-scripting-attacks-xss/
If $_GET['value']
is your vendor, consider using vendor
- it's semantic.
How I would implement this:
So, your approach isn't wrong, per se; it'll work. But here's how I would do it:
- Create a vendor plugin
- Create a custom controller action that takes an argument of
vendor
, using $this->getRequest()->getParams()
- which filters natively for nefarious stuff
- Set the output type of the controller to text/html, set to a blank theme that has no script includes or layout elements (structural blocks, etc.)
Or, instead of rolling your own, use the Unirgy Marketplace plugin which does what you're trying to do - and does it very well!
http://www.unirgy.com//products/umarketplace/magento-multi-vendor-marketplace
Best Answer
Follow below steps for creating popup window, you will need to create your block for displaying the attributes.
add include below files using layout xml
below is the prototype function which will invoke the widowbox
invoke function using below code