How to show a module in productdetails page only in virtuemart - virtuemart

I want to show a level2 categories only in product details page in virtuemart,but there is no specific product details page

You will need a component like Metamod and use a recipe like:
$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ($vm->check( "pagetype = productdetails" ) ) { return 99; // module id }
Without Metamod you could use the following:
if (JRequest::getVar('view')=='productdetails') {
jimport('joomla.application.module.helper');
$module = &JModuleHelper::getModule('mod_custom','Your module name');
echo JModuleHelper::renderModule($module);
}
Good Luck!

Related

Magento _searchCriterias cannot be changed

I'm building a custom search results page, and I have the IDs of all products that have to be included in the results. I want to override the default search criteria, and yes, I can override $this->_searchCriterias, but it does not change the results page itself.
This is my custom code of CatalogSearch/Model/Advanced.php
public function getSearchCriterias()
{
$search = $this->_searchCriterias;
var_dump($search);
$search = array();
if(isset($_GET['productid'])) {
$value = $this->getIdsFromSearchUrl($_GET['productid']);
if(is_array($value)){
foreach($value as $v){
if(is_numeric($v)){
$product = Mage::getModel('catalog/product')->load($v);
var_dump($product->getId());
$search[] = array('name'=>'Name','value'=>$product->getName());
}
}
} else {
if(is_numeric($value)){
$product = Mage::getModel('catalog/product')->load($value);
$search[] = array('name'=>'Name','value'=>$product->getName());
}
}
}
var_dump($search);
$this->_searchCriterias = $search;
return $search;
}
Any help appreceated.
The way I understand is that you want the site to always include some "featured products", which are not necessarily related to the search term.
I would suggest an alternative method instead of tampering with the search engine logic:
Create a block and template for displaying featured products.
Add the block to Search engine result page inside the product_list block (under catalogsearch_result_index)
Modify list.phtml and echo out the child block you just added.
Let me know if this helps.

Get Module ID or Title

I' am using Joomla 3, I have module called "Who we Are" and it's being displayed on position "top_row2". I' am trying to get this modules ID and modules Name.
After Searching I found few solutions which doesn't seem to work for me.
Solution 1
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('Who we Are');
echo $module->id;
Solution 2
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModules('Who we Are');
echo $module->id;
//Note the "s" in getModules
Solution 3
global $module;
$module->id;
$module->title;
I' am using this solutions on the override PHP files of this Module.
Location:: templates\corporate_response\html\mod_mymodule_item.php
You can define your own unique Class under "Module Class Suffix" and in your module override item page do a conditional to check which module is being rendered into the page
This might help explain calling modules in overrides.
To call a Joomla! module with the title in a template override:
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('position');
foreach($modules as $module) {
echo '<h3>' . $module->title . '</h3>';
echo JModuleHelper::renderModule($module);
}
This will call the module id.
echo $module->id;
This will call the module title in H3, adjust to what you need.
echo '<h3>' . $module->title . '</h3>';
This part will render the module.
echo JModuleHelper::renderModule($module);
You can get all modules by position and then select by title like this:
$module = false;
if ($modules = JModuleHelper::getModules('top_row2')) {
foreach ($modules as $module2) {
if ($module2->title == 'Who we Are') {
$module = $module2;
break;
}
}
}
if ($module) {
printf(
'Found module with name "%s" and id "%d"',
$module->name,
$module->id
);
} else {
echo "Found no matching module.";
}
If someone ever has the same question:
Within the modules code you can simply use the variable $module which contains all information about this specific module like id, title, position, ...

Magento: How to Print backend invoices like frontend as HTML?

I'm on Magento 1.7.0.2. How can I print invoices from backend with the same manner that frontend uses? I want it to be on HTML format not PDF.
Assuming that you want to print one invoice at a time from the admin order detail page
Create a custom admin module
Add a controller with the method below
public function printInvoiceAction()
{
$invoiceId = (int) $this->getRequest()->getParam('invoice_id');
if ($invoiceId) {
$invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
$order = $invoice->getOrder();
} else {
$order = Mage::registry('current_order');
}
if (isset($invoice)) {
Mage::register('current_invoice', $invoice);
}
$this->loadLayout('print');
$this->renderLayout();
}
Reference printInvoiceAction() in app/code/core/Mage/Sales/controllers/GuestController.php
Then in your custom layout.xml use <sales_guest_printinvoice> in /app/design/frontend/base/default/layout/sales.xml as your template
Then add a button with link to the following url (need to get invoice id from order) /customModule/controller/printInvoice/invoice_id/xxx
(Not tested, so let me know if you run into any issues)
You should create your custom css file for printing print.css. And you should add "Print Button", that will call window.print()

How to check if a Magento product is already added in cart or not?

I want to show popup when a product is first added to cart in Magento and don't want to show a popup if the product was added again or updated.In short, I want to know product which is going to be added in the cart is First occurence or not?
The answer largely depends on how you want to deal with parent/child type products (if you need to).
If you are only dealing only with simple products or you have parent/child type products and you need to test for child id's then:
$productId = 1;
$quote = Mage::getSingleton('checkout/session')->getQuote();
if (! $quote->hasProductId($productId)) {
// Product is not in the shopping cart so
// go head and show the popup.
}
Alternatively, if you are dealing with parent/child type products and you only want to test for the parent id then:
$productId = 1;
$quote = Mage::getSingleton('checkout/session')->getQuote();
$foundInCart = false;
foreach($quote->getAllVisibleItems() as $item) {
if ($item->getData('product_id') == $productId) {
$foundInCart = true;
break;
}
}
EDIT
The question was asked in a comment as to why setting a registry value in controller_action_predispatch_checkout_cart_add is not available to retrieve in cart.phtml.
Essentially registry value are only available through the life of a single request - you are posting to checkout/cart/add and then being redirected to checkout/cart/index - so your registry values are lost.
If you would like to persist a value across these then you can use the session instead:
In your observer:
Mage::getSingleton('core/session')->setData('your_var', 'your_value');
To retrieve the value
$yourVar = Mage::getSingleton('core/session')->getData('your_var', true);
The true flag being passed to getData will remove the value from the session for you.
In order check if the product is already in cart or not, you can simply use the following code:
$productId = $_product->getId(); //or however you want to get product id
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllVisibleItems();
$isProductInCart = false;
foreach($items as $_item) {
if($_item->getProductId() == $productId){
$isProductInCart = true;
break;
}
}
var_dump($isProductInCart);
Hope this helps!

Magento mass-assign products to category

As the title says,i need to mass-assign products to a category and from the admin i can only edit one product at a time; i dont know why it just doesnt work to mass add them from the "category products" tab in the category page.
Thats why i need another method that's fast,like using phpMyAdmin or something alike.
Any help?
Thanks in advance!
I created a simple script to do this outside of Magento. Be sure to test this first on a single product and make sure it looks as you'd expect.
// Load Magento
require_once 'path/to/app/Mage.php';
Mage::app();
// $productIds is an array of the products you want to modify.
// Create it however you want, I did it like this...
$productsIds = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('sku', array('like' => 'something'))
->getAllIds();
// Array of category_ids to add.
$newCategories = array(20);
foreach ($productIds as $id) {
$product = Mage::getModel('catalog/product')->load($id);
$product->setCategoryIds(
array_merge($product->getCategoryIds(), $newCategories)
);
$product->save();
}
If you wish to overwrite a product's existing categories, change array_merge(...) to just $newCategories.
I would shy away from tackling this problem from the database side of things. If you do go that direction make sure and take lots of backups and do it during low usage.
The following thread on the Magento forum identifies the very same problem. One poster recommends a raw sql approach with example. Again, I would be careful - make sure you take backups.
The answer I like best from the thread (posted by Magento MVP):
Go into the category you don’t want them in, find the product list.
Click the check boxes on the products you want to remove and select
delete from the little dropdown.
Now go into the category where you
do want them, go to the product list. Select the NO dropdown so it
shows items not in the category. You might have to do a selective
search to limit stuff and do it in a couple iterations. Click the
check boxes and tell it to add stuff.
You may as well do this using the magento API
This is the script I use for mass adding products. sku.txt contains one sku per line.
<?php
$wsdlUrl = "magento-root/index.php/api/soap/?wsdl";
$proxy = new SoapClient($wsdlUrl);
$sessionId = $proxy->login('apiuser', 'apipasswd');
$listOfDiscountedSKUFile = "sku.txt";
function readinFile($filePath)
{
$fp = fopen($filePath,'r') or exit("Unable to open file!");
$dataItems = array();
while(!feof($fp))
{
$dataItems[] = trim(fgets($fp));
}
fclose($fp);
var_dump($dataItems);
return $dataItems;
}
function addToCategory($sku,$categoryId)
{
global $proxy,$sessionId;
$proxy->call($sessionId, 'category.assignProduct', array($categoryId, $sku));
}
function IsNullOrEmptyString($question){
return (!isset($question) || trim($question)==='');
}
$categoryId = 82;//e.g.
$listOfSKU = readinFile($listOfDiscountedSKUFile);
foreach($listOfSKU as $sku)
{
addToCategory($sku,$category);
}
?>
I managed to resolve the problem with the following code :
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$x = 1171;
$y = 2000;
$categoryID = 4;
$productPosition = 0;
while($x <= $y) {
$write->query("REPLACE INTO `catalog_category_product` (`category_id`, `product_id`, `position`) VALUES ($categoryID, $x++, $productPosition)");
}
echo "The job is done";
?>
I hope the code is clear for everyone,if it's not,reply and i'll try to explain it.
#nachito : here it is.

Resources