Magento + Shopfusion singleton is empty - magento

I'm using Magento with Typo3 (Shopfusion). I've an extension for uploading order images it works in "pure" Magento but in Magento through Shopfusion.
I already debugged Magento as far as I could. In shopfusion the following Singleton leads into an empty array. I checked the getOrderAttachments from "RedPandaPlus_OrderAttachments_Block_Attachments" and found out that it isn't called
Singleton call:
$orderAttachments = Mage::getSingleton('redpandaplus_orderattachments/session')->getOrderAttachments();
Code of method:
class RedPandaPlus_OrderAttachments_Block_Attachments extends Mage_Core_Block_Template
{
,...
public function getOrderAttachments($orderId)
{
$collection = Mage::getModel('redpandaplus_orderattachments/orderattachment')->getCollection()
->addFieldToFilter('order_id', $orderId);
return $collection->toArray();
}
,...
}

As I can see from your code, you are missing the $orderId argument in your call:
$orderAttachments = Mage::getSingleton('redpandaplus_orderattachments/session')->getOrderAttachments();
To help you get the orderId I need to know where you are calling this method.

Related

Unable to call custom methods within extended Magento model

I'm attempting to customize the way pricing / tiered pricing is displayed in Magento CE 1.6.0.0.
I've followed the instructions in the second post of the link below to override Mage_Catalog_Model_Product_Type_Price
http://www.magentocommerce.com/boards/viewthread/16829/
Following is my custom model class:
class PHC_Price_Model_Price extends Mage_Catalog_Model_Product_Type_Price {
public function getPrice() {
echo "overridden getPrice method called<br>";
}
public function getPHCDisplayPrice($product) {
echo "custom price function called<br>";
}
}
I'm able to successfully call the overridden getPrice() function from my template file as follows:
$product = Mage::getModel("catalog/product")->load($_product->entity_id);
$displayPrice = $product->getPrice();
However, when I try to call my custom price function with
$product = Mage::getModel("catalog/product")->load($_product->entity_id);
$displayPrice = $product->getPHCDisplayPrice();
I get absolutely nothing. Can anyone tell me what I'm missing?
It't normal that you don't get a result. I would be amazed if this worked.
You are overriding the class Mage_Catalog_Model_Product_Type_Price, but in your example the $product variable is an instance of Mage_Catalog_Model_Product. That class does not have the method getPHCDisplayPrice and it calls the __call method and returns null.
You get the expected result when calling getPrice by accident. It is because the getPrice method in Mage_Catalog_Model_Product looks like this:
public function getPrice()
{
if ($this->_calculatePrice || !$this->getData('price')) {
return $this->getPriceModel()->getPrice($this);
} else {
return $this->getData('price');
}
}
So when you call it, it calls $this->getPriceModel()->getPrice($this) and $this->getPriceModel() returns an instance of your class.

magento get custom attribute label

I've a problem, I want to show the label of a custom attribute in the product page.
I explain me better, starting from this link because is what I want to do:
http://www.customy.com/blog/how-to-display-video-on-magento-product-page/
I want a video product in the sidebar of the product page, so I create a new custompage.phtml and i put this in the sidebar from catalog.xml, in my custompage.phtml I put this code to have the custom label:
getResource()->getAttribute('video')->getStoreLabel();?>
but I have this error:
"Fatal error: Call to a member function getResource() on a non-object in ..path//"
I have try different code but still have this problem.
I think that I forget to put something in my .phtml but I'm new of Magento and I don't know what!
Thank in advance!
Since $_product didn't work then you'll need to load the object before attempting to access the attribute. Try this:
$product_id = Mage::registry('current_product')->getId();
$_product=Mage::getModel('catalog/product')->load($product_id);
echo $_product->getResource()->getAttribute('video')->getStoreLabel();
If you don't have access to the product model, I wrote a small query to get it from DB. This could be done better, but should be a decent starting point for your class:
protected $_dbConn;
public function __construct()
{
$this->_dbConn = Mage::getSingleton('core/resource')->getConnection('core_read');
}
public function getAttributeLabel($code)
{
$query = "
SELECT b.value
FROM eav_attribute a
JOIN eav_attribute_label b
ON a.attribute_id = b.attribute_id
WHERE a.attribute_code = '".$code."'";
return $this->_dbConn->fetchOne($query);
}

Magento, access functions in Mage_Core_Helper_Abstract

Im new to Magento
Just installed this plugin http://shop.bubblecode.net/magento-attribute-image.html
All is going well, so on my product view page I run the following code to get my attribute ids
$ids = $_product->getData('headset_features');
Now the above plugin states it comes with this helper http://shop.bubblecode.net/attachment/download/link/id/11/
The function in this class I need to use is
public function getAttributeOptionImage($optionId)
{
$images = $this->getAttributeOptionImages();
$image = array_key_exists($optionId, $images) ? $images[$optionId] : '';
if ($image && (strpos($image, 'http') !== 0)) {
$image = Mage::getDesign()->getSkinUrl($image);
}
return $image;
}
I am really struggling to make use of this function.
I noticed in the helper class Bubble_AttributeOptionPro_Helper_Data extends Mage_Core_Helper_Abstract
So here is what I thought should work
echo Mage::helper('core')->Bubble_AttributeOptionPro_Helper_Data->getAttributeOptionImage($ids[0]);
But its not working for me, it kills the page, can someone please tell me how to access the function.
Thanks in advance.
UPDATE:
Just tried $helper = Mage::helper('AttributeOptionPro'); which also kills the page
Based on the helper classgroup for this module (bubble_aop, defined in the config), you can instantiate the helper class as follows:
$helper = Mage::helper('bubble_aop');
However I do not see anything in the class definition which gets it to pull data from the product entity.
You need to look into the module's etc folder and in config.xml you should have a node called helpers under config > global. The first child of that node (so that is before class node) is the name you should use to instantiate your helper and call your method so you would have something like Mage::helper('child_node_name')->getAttributeOptionImage($optionId);
Most of the helper classes extend Mage_Core_Helper_Abstrat which is abstract (can't be instantiated). If you run get_class(Mage::helper('core')) you will get Mage_Core_Helper_Data, because actually the default helper class in a module is Namespace/Module/Hepler/Data.php

calling a function within a class with a Joomla module

I have a Joomla helper class that I'm using for module development with a method I'm trying to call:
class modCamcloudReferralHelper
{
/*
* Sanitize email form
*/
public function isInjected($str) {
$inject = "/(\r|\t|%0A|%0D|%08|%09)+/i";
return (preg_match($inject, $str) > 0);
}
public static function sendEmail() {
$jinput = JFactory::getApplication()->input;
$email = $jinput->post->get('email', '', 'STRING');
//check email is fine
if (isInjected($email)){ //never get into this code and it causes some sort of failure
echo "blah";
}
}
}
Simple, right? But this code just gives me a blank page and I don't see any errors...anywhere. I can instead just put this code right into my sendEmail function and it works just fine:
$inject = "/(\r|\t|%0A|%0D|%08|%09)+/i";
if (preg_match($inject, $email) > 0){
echo "This works";
}
I've had this problem with my Joomla components I've built before. For some reason calling this function from inside the same class is not working. It must be a Joomla thing...or I'm going nuts. Any ideas?
You should call the method with a reference to its container, even if it's local.
So the right syntax here is:
if (self::isInjected($email))
of from another class:
modCamcloudReferralHelper::isInjected(
This is good for helpers: just make sure you declare the method you are invoking as static
public static function isInjected($str) {
If however you're calling a method on an instantiated class (a view, a template, a model, you should use
$this->method()

Customer session is different in different parts of a Magento website

I have a function inside of a Helper in Magento that returns whether or not a customer attribute equals one.
Here is my Helper class
class Nie_Nie_Helper_Data extends Mage_Core_Helper_Abstract {
public function isNieAdmin() {
if(Mage::getSingleton('customer/session')->getCustomer()->getNieAdmin() == 1) {
return true;
} else {
return false;
}
}
}
Now when I call this function from a class that extends Mage_Core_Block_Template, everything seems to work fine. However when I try to use this inside one of my controllers, it does not work. In fact when I do Mage::getSingleton('customer/session')->getCustomer()->debug() the only variable that is returned is the website_id.
Does anyone know what I have to do in order to get this to work?
At the time of the controller the session objects are not yet initialised (although the session variable must be) so it returns a blank model. My guess is the website_id is deliberately set in the creation of a customer object to act as a default.
You could access $_SESSION['customer'] directly to find what you need, but that is messy. An alternative would be to do what you want in an event that occurs later.
I hope someone can come up with a better answer than mine.
Ok it looks like I had to load up the session myself. I had to put the following in my functions:
Mage::getSingleton('core/session', array('name' => 'frontend'));
Hope this helps.

Resources