IM having a weird instance where a page created via the CMS backend is not showing on the site. This is only happening on one of the pages out of 40 that i have newly created. I have tried deleting the page and remaking it but this produces the same error. I have also tried changing the status to Disabled and back to Enabled but that didn't work either.
I simply just get a white page with no errors in the console or otherwise. Any thoughts?
Your post is a little light on the details a programmer needs to help you, so here's how I'd debug this
Magento looks for a CMS page in the following method.
#File: app/code/core/Mage/Cms/Model/Resource/Page.php
public function checkIdentifier($identifier, $storeId)
{
$stores = array(Mage_Core_Model_App::ADMIN_STORE_ID, $storeId);
$select = $this->_getLoadByIdentifierSelect($identifier, $stores, 1);
$select->reset(Zend_Db_Select::COLUMNS)
->columns('cp.page_id')
->order('cps.store_id DESC')
->limit(1);
return $this->_getReadAdapter()->fetchOne($select);
}
This code generates a SQL query that compares the identifier in the URL with what it can find in the cms_page table. For someone reason this query is returning zero rows in your Magento instance. Add some temporary debugging code to output the SQL query
$select->reset(Zend_Db_Select::COLUMNS)
->columns('cp.page_id')
->order('cps.store_id DESC')
->limit(1);
echo '<pre>';
echo $select->__toString();
echo '</pre>';
exit(__METHOD__ . '::' . __LINE__);
return $this->_getReadAdapter()->fetchOne($select);
and determine why your query is returning no rows.
Related
===
UPDATE:
I think now I am literally just trying to get a database value into my component php files, but again, there seems to be very little documentation that can give an example of a function that will return this info like there is in Wordpress.
So I have a table called membersarea_countries that will have records of differnt countries I want to store values for.
I've read about JTable and other things, but how can I simply just bring back the records from this table?
$row = JTable::getInstance('membersarea_countries', 'Table', array());
But this returns a boolean of 0.
I'd really appreciate some help if anyone can.
===
I've been following what several online guides explain, which are all pretty much the same thing, but I never seem to return the values that I'm expecting.
In Components > Members Area (my component), I have a table set up to allow me to enter a record for each country, and then store a uniqueRef, signature, and URL within that record. (for GeoIP purposes).
I've created the first record, however when I try to use the following code, which the tutorials suggest, I don't see any of my fields within this:
$app = JFactory::getApplication();
$params = $app->getParams();
$uniqueRef = $params->get('uniquereference');
$signature = $params->get('signature');
This is all I see in NetBeans:
There's nothing about $app, and no sign of the fields I've got in the Joomla backend.
I don't understand what's happening, or exactly what I should be doing here. Wordpress uses a simple get_option function. Can anyone try and help me?
Below is the link to the detailed document about JTable -
https://docs.joomla.org/Using_the_JTable_class
Firstly you need to create JTable instance using below code and also change table file name to membersareacountries.php
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_membersarea/tables');
$row = JTable::getInstance('Membersareacountries', 'Table', array());
JTable Class in this file /administrator/components/com_membersarea/tables/membersareacountries.php-
<?php
defined('_JEXEC') or die();
class TableMembersareacountries extends JTable
{
public function __construct($db)
{
parent::__construct( '#__membersarea_countrie', 'id', $db );
}
}
Then you can use load method to get any records. This accepts primary key value of that table -
$id = 1;//change id as per your record
$row->load($id);
//read data
echo $row->id;
echo $row->title;
i am trying to update meta description for different store but magento keep showing error :
Product with URL key already exist.
what i am trying to do i have two stores on one magento. so we want seprate meta information for different stores. so when i try to update meta info for specific store then shows me error. any one facing same problem :
$pid = Mage::getModel('catalog/product')->getResource()->getIdBySku($sku);
$product = Mage::getModel('catalog/product')->load($pid);
if($product)
{
$product->setStoreId(6);
$product->setmeta_keyword($newKeyWord);
$product->setmeta_description($newmeta_metadescription);
try {
$product->save();
echo 'Product Updated successfully --- '.$sku."\n";
}
catch (Exception $ex) {
echo $ex->getMessage();
}
There are lot of issue in your code:
Setter function is wrong:
$product->setMetaKeyword($newKeyWord);
$product->setMetaDescription($newmeta_metadescription);
Best way to do this:
$product = Mage::getModel('catalog/product')->load($pid);
Please use below format,which more faster then your code
$product->addAttributeUpdate($Attributecode, $value, $storeId)
then
$product->addAttributeUpdate('meta_keyword', $newKeyWord, $storeId=6);
$product->addAttributeUpdate('meta_description', $newmeta_metadescription, $storeId=6);
No need use save() function in this case.
I've been looking all over the web on how I would go about retrieving filtered products and then get their respective attributes using getAdditionalData. Here's what I do:
$_collectionProduct=Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter('status', array('eq' =>1))
->addAttributeToFilter('attribute_set_id',9)
->addAttributeToSelect('*');
This works and retrieves all the filtered products. However, now I need their attributes so I am looping
foreach ($_collectionProduct as $products) {
$_additional = $product->getAdditionalData();
}
What happens is that $_additional returns NULL.
Another scenario I have tried is the following
foreach ($_collectionProduct as $_products) {
$product= Mage::getModel("catalog/product")->load($_product->getId());
$_additional = $product->getAdditionalData();
}
This example still displays NULL. Would really appreciate if somebody would have a solution to the dilemma. Thanks.
I actually figured out why it wasn't working. It appears that getAdditionalData() is not really attached to a specific product. The product view is calling this function from core file. The actual function I needed to use was getAttributes().
I have a customer product page that literally lives beside the catalog/product/view.phtml page. It's basically identical to that page with a few small exceptions. It's basically a 'product of the day' type page so I can't combine it with the regular product page since I have to fetch the data from the DB and perform a load to get the product information
$_product = Mage::getModel('catalog/product')->load($row['productid']);
To make a long story short, everything works (including all children html blocks) with the singular exception of the related products.
After the load I save the product into the registry with
Mage::register('product', $_product);
and then attempt to load the related products with:
echo $this->getLayout()->createBlock('catalog/product_view')->setTemplate('catalog/product/list/related.phtml')->toHtml();`
All of which give back the error:
Fatal error: Call to a member function getSize() on a non-object in catalog/product/list/related.phtml on line 29`,
and line 29 is
<?php if($this->getItems()->getSize()): ?>`.
Any help getting the relateds to load would be appreicated.
I didn't quite follow what you're trying to do, but I know why you're getting your errors. You're creating a block whose class-alias/class is
catalog/product_view
Mage_Catalog_Block_Product_View
but you're setting this block's template as
catalog/product/list/related.phtml
The stock catalog/product/list/related.phtml template was built to be used with a catalog/product_list_related Block only, and not a catalog/product_view Block.
If you take a look at the class definition for a catalog/product_list_related Block (which is a Mage_Catalog_Block_Product_List_Related), you can see that there's a getItems() method.
public function getItems()
{
return $this->_itemCollection;
}
which returns a collection. The collection is set in the _prepareData method
protected function _prepareData()
{
$product = Mage::registry('product');
/* #var $product Mage_Catalog_Model_Product */
$this->_itemCollection = $product->getRelatedProductCollection()
...
This collection is never set with a catalog/product_view Block, which is why you're getting your errors.
In your code above, if you switch to creating a catalog/product_list_related block, your errors should go away.
public function relatedproductsAction(){
$this->loadLayout();
$relatedBlock = "";
$rec_prod_id = Mage::getSingleton('checkout/session')->getLastAddedProductId(true);
$_product = Mage::getModel('catalog/product')->load($rec_prod_id);
Mage::register('product', $_product);
$relatedBlock = $this->getLayout()->createBlock('catalog/product_list_related')->setTemplate('catalog/product/related.phtml')->toHtml();
echo $relatedBlock;
exit;
}
Getting html of related block through ajax call, right after when product is added to cart. might be relatively helpful.
Here is my function. It is very simple.
function load_data() {
$query = $this->db->query('SELECT * FROM configurations WHERE username="' . $this->session->userdata('username') . '"');
return $query;
}
My controller has this line of code:
$data['query'] = $this->configurations->load_data();
In my view, I tried:
foreach($query->result_array() as $row) {
echo $row->first;
}
But I get an error that I am trying to get a property of a non-object. Isn't the query being returned from the model as an object?
You should use $query->result_array, row_array, result, or row otherwise your returning the object intead get the results. Check the CI manual.
You are returning the results as array and using $row as object!
Try:
foreach($query->result() as $row) {
Refer.
Try changing $this->load->model('login/configurations', '', TRUE); to $this->load->model('login/configurations', 'configurations', TRUE); and see if it works. If it does, it is related to how you're extending your model class. That is, it would be related to what name you give inside configurations.php.
Hope this helps.
Your undefined variable error tells me that your query might not be running correctly. To diagnose...enable the profiler to check your query.
From the documentation:
$this->output->enable_profiler();
Permits you to enable/disable the
Profiler, which will display benchmark
and other data at the bottom of your
pages for debugging and optimization
purposes.
To enable the profiler place the
following function anywhere within
your Controller functions:
$this->output->enable_profiler(TRUE);
When enabled a report will be
generated and inserted at the bottom
of your pages.
Your query will be shown at the end of
the page
Double check your query syntax to make sure it is running properly, and
your code in it's current state is returning an object of objects and arrays:
print_r($query)
CI_DB_mysql_result Object
(
[conn_id] => Resource id #29
[result_id] => Resource id #39
[result_array] => Array
(
)
[result_object] => Array
(
)
[current_row] => 0
[num_rows] => 3
[row_data] =>
)
you need to access the individual properties to get to the actual data.
$result=$query->result();
print_r($result);
should do it
Had this issue before - basic problem is that if the Query returns no result set then $query->result_array() == NULL
NULL is not a list and can't be processed in a foreach.
I have found that checking for this condition solves this issue.
From your question, you are getting the result as a pure array (result_array) but printing the data as object ($row->first).
result() or row() is returning in object but result_array is returning in array.
change your view part like,
foreach($query->result_array() as $row) {
echo $row['first'];
}
or if you want to use an object then,
foreach($query->result() as $row) {
echo $row->first;
}
Generating Query Results in Codeigniter