Add module to subpage in Joomla - joomla3.4

I have a module which I add from admin panel to some subpage. After that some subpages show properly content with this module but some subpages after click on it open blank, white page with no content inside. I don't know what caused that problem. Why some subpages with this module work properly and some show blank page?
This is what I see on page:
Fatal error: Cannot redeclare class ModProductsMenuHelper in /opt2/data-dev/modules/mod_products_menu/helper.php on line 15
Thank you for help!
This is my code
<?php
/**
* Slajder class for Hello World! module
*
* #package Joomla.Tutorials
* #subpackage Modules
* #link http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module
* #license GNU/GPL, see LICENSE.php
* mod_helloworld is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
class ModProductsMenuHelper
{
/**
* Retrieves the hello message
*
* #param array $params An object containing the module parameters
*
* #access public
*/
public function getProducts($params)
{
$lang = JFactory::getLanguage();
$langTag = $lang->getTag();
$app = JFactory::getApplication();
$isSMB = $app->get('isSMB');
$parentMenuId = $langTag == 'pl-PL' ? 107 : 103;
$results = $this->getChildren($parentMenuId, $langTag);
return $results;
}
private function getChildren($parentId, $langTag){
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query
->select(array('id', 'title', 'path', 'alias'))
->from($db->quoteName('#__menu'))
->where("(language = '*' OR language= ".$db->quote($langTag).") AND published = 1 AND parent_id=".$parentId)
->order($db->quoteName('lft') . ' ASC, '.$db->quoteName('id') . ' ASC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();
foreach ($results as $key=>$val){
$results[$key]->children = $this->getChildren($val->id, $langTag);
}
return $results;
}
}

From what I can gather you have created a module and assigned it to specific pages. You haven't mentioned what the contents of the module are (custom html etc).
Have you assigned the module to the correct pages in the 'module assignment' tab? Have a look at this question and answer as it explains how to do that.
If you are seeing a white page, i'd suggest enabling error reporting in Joomla. This should provide you with additional useful information about the error.
If you have a link to your website that would be helpful, and the version of Joomla you are using.

Related

Use Doctrine SQLLogger in TYPO3 Backend to log all executed SQL queries

We are facing very long load times for the record list view in many pages. To understand what is causing this, we want to analyze the SQL queries executed. (Ultimately, we might want a admin panel for the backend).
Theoretically, Doctrine DBAL supports hooking SQLLogger, but we don't know where the proper Class replacement/injection for this would be.
We did find the ability to patch the file typo3/cms/typo3/sysext/core/Classes/Database/Connection.php and simply create a new method overwriting the parent:
/**
* Debug all the things
*
* If the query is parametrized, a prepared statement is used.
* If an SQLLogger is configured, the execution is logged.
*
* #param string $query The SQL query to execute.
* #param array $params The parameters to bind to the query, if any.
* #param array $types The types the previous parameters are in.
* #param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional.
*
* #return \Doctrine\DBAL\Driver\Statement The executed statement.
*
* #throws \Doctrine\DBAL\DBALException
*/
public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null) {
$fp = fopen('/var/www/html/logs/mysql.log', 'a'); fwrite($fp, '[QUERY-DOCTRINE] ' . $query . "\n"); fclose($fp);
return parent::executeQuery($query, $params, $types, $qcp);
}
But that approach isn't really portable and requires to patch composer-generated vendor files. Also, it's lacking proper raw logging and the abilities of sophisticated SQLLoggers. So somewhere we should be able to call the Doctrine Configuration class methods?
You can modify/extend the connection class and make the database layer use yor custom class with the config option of wrapperClass that is part of the configuration for the database connection.
work in progress #medz, just created an extension.
https://packagist.org/packages/datenbetrieb/sqllog
requires some config
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['wrapperClass']= \Datenbetrieb\Sqllog\Database\Connection::class;
$GLOBALS['TYPO3_CONF_VARS']['LOG']['Datenbetrieb']['Sqllog']['Database']['Logging']['writerConfiguration'] = array(
\TYPO3\CMS\Core\Log\LogLevel::DEBUG => array(
'TYPO3\\CMS\\Core\\Log\\Writer\\FileWriter' => array(),
),
);

PHP: Generate Laravel Paginator Secure (HTTPS) Links

I'm developing an app using Laravel 4.2 over HTTPS with secure routes and redirects. I'm using Paginator to paginate results, but the links rendered in the view points to the http pages, how can we force Paginator to generate https links?
I had this issue today and found this global solution.
In your AppServiceProvider::boot method you can add the following to force https on pagination links
$this->app['request']->server->set('HTTPS','on');
If your current page is served over HTTPS, then the pagination URLs generated should use that schema.
However if you're using a proxy that does not pass the correct headers, the Request class responsible for determining if the connection is secure, might not report it as such. To determine if the request is detected as secure use Request::secure(). If that returns false, try using Laravel Trusted Proxies.
If that does not work you can force the pagination URLs with setBaseUrl as follows:
$results->paginate();
$results->setBaseUrl('https://' . Request::getHttpHost() . '/' . Request::path());
Add a custom presenter ZurbPresenter.php in app/helpers/ (you can place it inside other directory provided its path is included in to ClassLoader::addDirectories()):
<?php
class ZurbPresenter extends Illuminate\Pagination\Presenter {
/**
* Get HTML wrapper for a page link.
*
* #param string $url
* #param int $page
* #param string $rel
* #return string
*/
public function getPageLinkWrapper($url, $page, $rel = null)
{
$rel = is_null($rel) ? '' : ' rel="'.$rel.'"';
if (strpos($url, "http://") === 0) {
$url = "https://" . ltrim($url, "http://");
}
return '<li><a href="'.$url.'"'.$rel.'>'.$page.'</a></li>';
}
/**
* Get HTML wrapper for disabled text.
*
* #param string $text
* #return string
*/
public function getDisabledTextWrapper($text)
{
return '<li class="disabled"><span>'.$text.'</span></li>';
}
/**
* Get HTML wrapper for active text.
*
* #param string $text
* #return string
*/
public function getActivePageWrapper($text)
{
return '<li class="active"><span>'.$text.'</span></li>';
}
}
Notice the getPageLinkWrapper() has a logic to replace http by https.
Create a view file to use the presenter. Inside app/views create a file zurb_pagination.php with following content:
<?php
$presenter = new ZurbPresenter($paginator);
$trans = $environment->getTranslator();
?>
<?php if ($paginator->getLastPage() > 1): ?>
<ul class="pager">
<?php
echo $presenter->getPrevious($trans->trans('pagination.previous'));
echo $presenter->getNext($trans->trans('pagination.next'));
?>
</ul>
<?php endif; ?>
Finally change your app config to use the new presenter in app\config/view.php for pagination:
'pagination' => '_zurb_pagination_simple',
I use a similar approach for my website and you can verify it's working here.

Outside link for Add to Cart

We want to get an outside link for a Magento-store page, that would add to cart an item that's linked from a PDF link (it's a technical drawing with some parts that can be ordered separately)
I see that Magento uses JavaScript onclick="productAddToCartForm.submit(this)", but it can not be triggered to the specific item like this.
Is there any way this can be solved?
BR-:g
This is the basic url to call:
www.example.com/checkout/cart/add?product=[id]&qty=[qty]
If you want more details on how to do it with options etc. take a look here:
http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/adding_a_product_to_the_cart_via_querystring
You can give add to cart url like:
<?php echo $this->helper('checkout/cart')->getAddUrl($_product);?>
You can always loop over your product collection and ask the checkout/cart helper for the url:
$collection = Mage::getResourceModel('catalog/product_collection');
/* #var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
//... add filters to collection as appropriate
$cartHelper = Mage::helper('checkout/cart');
/* #var $cartHelper Mage_Checkout_Helper_Cart */
foreach( $collection as $product ){
/* #var $product Mage_Catalog_Model_Product */
$atcUrl = $carthelper->getAddUrl($product);
//... do what you need to with the above value (echo, fwrite, etc);
}
Note that you can also pass in product-type-specific options as a second param.

Magento - Add to Cart Error

I'm getting this error after add/remove item to/from cart. Add to Cart button does ajax call to add item to the cart. This kind of json string which will be used in top cart:
I'm stuck. Can you tell me where should I start from to debug?
the "Add to Cart" button does not work asynchrounisly in Magento's default behaviour. That means that you installed/developped a module to do this. For us to help you, we need to know what is it.
Anyways, this looks like a Zend_Dump or maybe a die: make a search in your files for these strings and see what comes up
Use Netbeans and Xdebug.
http://wiki.netbeans.org/HowToConfigureXDebug
Place a breakpoint on the /app/code/core/Mage/Sales/Model/Quote.php inside this function:
/**
* Adding catalog product object data to quote
*
* #param Mage_Catalog_Model_Product $product
* #return Mage_Sales_Model_Quote_Item
*/
protected function _addCatalogProduct(Mage_Catalog_Model_Product $product, $qty = 1)
{
$newItem = false;
$item = $this->getItemByProduct($product);
if (!$item) {
$item = Mage::getModel('sales/quote_item');
$item->setQuote($this);
if (Mage::app()->getStore()->isAdmin()) {
$item->setStoreId($this->getStore()->getId());
}
else {
$item->setStoreId(Mage::app()->getStore()->getId());
}
$newItem = true;
}
/**
* We can't modify existing child items
*/
if ($item->getId() && $product->getParentProductId()) {
return $item;
}
$item->setOptions($product->getCustomOptions())
->setProduct($product);
// Add only item that is not in quote already (there can be other new or already saved item
if ($newItem) {
$this->addItem($item);
}
return $item;
}
HTH

Magento Limit Number of Products in Home page

I have added this code {{block type="catalog/product_list" category_id="25" template="catalog/product/list.phtml"}} in cms home page
I want to limit no of products to display to nine to this category only.How can i do that?
I don't think there is a value you can pass into the block tag to limit it. I would suggest making a new list.phtml file that limits it there.
Let me look at the code real quick.
Ok. If you were to copy the file /app/design/frontend/default/default/template/catalog/product/list.phtml
to
/app/design/frontend/default/default/template/catalog/product/list-limit.phtml
and then edit it as follows:
LINE49: After the foreach
<?php if($_iterator >=9) { break; } ?>
LINE94: Where $_collectionSize is assigned change to:
<?php $_collectionSize = main(9, $_productCollection->count()) ?>
Line97: After the foreach
<?php if($i >= 9) { break; } ?>
It should achieve what you desire regardless of Grid or List view.
... shortly an alternative method ...
The other way would be to edit the List.php file that loads the product list that the phtml file presents. Block Type of 'catalog/product_list' means you need the file:
/app/code/core/Mage/Catalog/Block/Product/List.php
In there you will see the method getLoadedProductCollection, which calls _getProductCollection. That code could be edited to filter/limit the number of returned products. You would want to make a copy of that file though, and update the block link in your page. Don't add underscores to the name, as that will require the file be put in a subdirectory.
Hope this helped.
Following on from the previous answer, I seem to have acheived this by editing the List.php by adding the following after line 96.
return $this->_productCollection
->setPageSize($this->getProductsCount());
}
/**
* Set how much product should be displayed at once.
*
* #param $count
* #return Mage_Catalog_Block_Product_New
*/
public function setProductsCount($count)
{
$this->_productsCount = $count;
return $this;
}
/**
* Get how much products should be displayed at once.
*
* #return int
*/
public function getProductsCount()
{
if (null === $this->_productsCount) {
$this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
}
return $this->_productsCount;
}
and adding this after line 43
/**
* Default value for products count that will be shown
*/
const DEFAULT_PRODUCTS_COUNT = 100;
/**
* Products count
*
* #var null
*/
protected $_productsCount;
I got the codes from new.php

Resources