getAddressesHtmlSelect() Change - Magento - magento

I've been trying to edit the getAddressesHtmlSelect() function (found in code/core/Mage/Checkout/Block/Onepage/abstract.php) in order to enable the "new address" to display first in the dropdpown created.
I've located the place it needs to be changed in, but I can't figure out how to do that. Can anyone help? The code in question is:
$select = $this->getLayout()->createBlock('core/html_select')
->setName($type.'_address_id')
->setId($type.'-address-select')
->setClass('address-select')
->setExtraParams('onchange="'.$type.'.newAddress(!this.value)"')
->setValue($addressId)
->setOptions($options);
$select->addOption('', Mage::helper('checkout')->__('New Address'));
return $select->getHtml();

Look for magento block rewrite.
You need to rewrite Mage_Checkout_Block_Onepage_Billing and Mage_Checkout_Block_Onepage_Shipping
Just rewrite this blocks in your custom module and define new logic for getAddressesHtmlSelect
function
To set "New address" as default one:
Assembled working sample for you.
array_unshift($options, array('value' => '', 'label'=> Mage::helper('checkout')->__('New Address')));
$select = $this->getLayout()->createBlock('core/html_select')
->setName($type.'_address_id')
->setId($type.'-address-select')
->setClass('address-select')
->setExtraParams('onchange="'.$type.'.newAddress(!this.value)"')
->setOptions($options);
return $select->getHtml();

Related

Magento getAttributeName / Text

I'm playing arround with magento product attributes.
What i'm trying to do is getting an "Unique Product Number" attached to the same " Unique Video Number" That works perfectly.
The same goes for an Dropdown Attribute using the following code.
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/avembed.js"></script>
<div class="av_videoplayer" data-av-search-ean="<?php echo $_product->getAttributeText('DropDown_Atribute') ?>"></div>
But as soon as i try it with an TextBox or TextField it fails to return an output.
I have been using getAttributeName to make it happen but i can't seem to get it working or find the anwser to do this.
Any tips on what i might be doing wrong here?
Thanks in advance!
Magento provides magic getters and setters, so for most product attributes, you can retrieve them using the attribute name, preceded by get. For example:
$freeShipping = $_product->getFreeShipping();
The alternative to this is the method you are using, getAttributeText.
$freeShipping = $_product->getAttributeText('free_shipping');
HOWEVER, the attribute must be in the product collection, which most custom attributes are not. When you setup your attribute, you need to set the option Visible on Product View Page on Front-end to Yes.
Failing that, you can recreate the product collection (in your own helper, for example) and add your attribute(s) manually as follows:
public function getMyProductCollection( $skuArray ) {
$products = Mage::getResourceSingleton('catalog/product_collection')
->addAttributeToSelect(
array(
'free_shipping',
'list_price',
'manufacturer',
'name',
'price',
'special_price',
'special_from_date',
'special_to_date',
'thumbnail'
)
)
->addAttributeToFilter(
'sku', array( 'in' => $skuArray )
)
->load();
return $products;
}
You can then use the public function as follows:
$_productObj = $this->helper('my_helper')->getMyProductCollection(
$_productSkus
);
Understand that I'm describing the principle, this code is not copy + pastable. Hope that helps.

Including magento header outside of magento. Problems with $this->getChildHtml()

I have researched this topic pretty thoroughly but can't find an answer.
I am trying to include a Magneto head into a WordPress page. I created a new wordpress template and added the following code to it.
try {
require_once ABSPATH . '/app/Mage.php';
if (Mage::isInstalled()) {
$mage = Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));
if(Mage::getDesign()->designPackageExists('xxx')) {
Mage::getDesign()->setPackageName('xxx');
Mage::getDesign()->setTheme('xxx');
}
// init translator
$mage->getTranslator()->init('frontend');
// init head
$head = $mage->getLayout()->getBlockSingleton('page/html_head');
} }
Then a bit further down in the template I have
echo $head->toHtml();
Now what is happening is some parts of the head are being echoed and some parts are not.
When I go into head.phtml and try to figure out what is happening I notice that any line that contains
$this->getChildHtml()
does not get echoed.
I looked at this example and noticed that the author is manually adding the html and CSS. Why is this? Why don't they get added automatically? Is this a related problem
Thanks
To show a block that is generated inside the header block, you need to first create it, then set it as child of the header block.
eg. Here is how I display within Wordpress a Magento header block, including the currency drop-down block that was generated by getChildHtml() inside the original header.phtml:
Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton("customer/session");
$layout = Mage::getSingleton('core/layout');
$headerBlock = $layout->createBlock('page/html_header')->setTemplate('page/html/header.phtml');
$currencyBlock = $layout->createBlock('directory/currency')->setTemplate('currency/currency.phtml');
$headerBlock->setChild('currency_selector', $currencyBlock);
$headerBlock = $headerBlock->toHtml();
Then you can write the block where you need it on the page:
echo $headerBlock;
I know it's a little late but hopefully this helps others with this issue.
Are you familiar with how magento layouts are rendered? With $head = $mage->getLayout()->getBlockSingleton('page/html_head'); you create a new block without any children. That's why the author needs to add JS and CSS again. To load the default head block have a look at this thread Load block outside Magento. You can load it with $layout->getBlock('head')->toHtml();.

Hide Products without images magento

I have followed this answer to hide products without images on the category listing page. It worked nicely for a while.
Now, for some reason it seems the products without images are still showing up on the listing page.
Any ideas as to why this may be happening?
Note:
The same list.phtml page is being used.
Thank you.
Add the following to list.phtm:
//$_productCollection=$this->getLoadedProductCollection();
$_productCollection = clone $this->getLoadedProductCollection();
$_productCollection->clear()
->addAttributeToFilter('small_image', array('neq' => 'no_selection'))
->load();
This answer recommended the following:
->addAttributeToFilter('image', array('neq' => 'no_selection'))
Whereas I have set it to:
->addAttributeToFilter('small_image', array('neq' => 'no_selection'))
The reason the previous answer did not work was because the product collection doesn't load the regular image, and therefore the regular image cannot be added as an attribute to filter, so instead, I added the small_image as the attribute to filter.
You can also try R.S's answer where he adds the image to the page and hence the collection. You may have to also add all attributes using:
->addAttributeToSelect('*')
There are some tricks to keeping Magento in line. One thing I've learned is that the Magento Model will change for many different reasons, and its kinda hard to figure out why. There are better ways to do this (modifying the collection, etc) but it sometimes just does not work and you don't have days to figure out why.
If you want a surefire way to make sure your image exists, use the following code... It may not be the 'magento way' but it works, and I tested it on my site (Magento EE 1.12). Put it in a function, or use it directly in your phtml if you want!
It basically just makes sure the URL exists.
$exists = false;
$entity_id = 8800;
$product = Mage::getModel('catalog/product')->load($entity_id);
$mediaUrl= Mage::getBaseUrl('media');
$imageUrl = $mediaUrl . "catalog/product" . $product->getImage();
$file_headers = #get_headers($imageUrl);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = false;
}
else {
$exists = true;
}
var_dump($exists);
var_dump($imageUrl);
echo '<img src="' . $imageUrl . '" />';
$exists will either be true (image does exist) or false (image does not)
I think that the issue is that you are trying to get the 'image' (base image) property on the list.phtml (by default i can only access the thumbnail, small_image).
On list.phtml (not loading the full product resource like on view.pthml)
echo $_product->getImage() //null
echo $_product->getThumbnail() // path/name.jpg
echo $_product->getSmallImage() // path/name.jpg
I think you may need to add adding something like this to app/design/frontend/default/yourtheme/layout/catalog.xml
<action method="addAttribute"><name>image</name></action>
See How to get access to custom Image Attribute in list.phtml in Magento

Magento Backendgrid: Click on a data entry and display its data

I used this tutorial (especially Lesson 6 and 7) to create my own backend grid for Magento: http://www.pierrefay.com/magento-developper-guide-howto-tutorial-5
Everything works fine. I can create new data entries for my grid. If I click on an entry the VarienForm is displayed again but all the text fields are empty. This seems as if Magento thinks I want to edit all the text fields. But actually I want it to display the entry data first. But it only shows empty fields.
Can anyone help me out here? Thanks a lot!
There are a lot of things that could be wrong with your implementation, but it's impossible to say without seeing your code. Nevertheless, I'm going to try. That tutorial looks fine to me, but I haven't run the code so I can't be sure. I'm inclined to think you might have just missed something. Working in grids & tabs can be particularly delicate at the best of times.
It does sound to me like it's one of two things. It sounds like either
A) Your model data is not being stored in the registry. That means the problem is in this part of the code:
<?php
class Pfay_Test_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
...
public function editAction()
{
$testId = $this->getRequest()->getParam('id');
$testModel = Mage::getModel('test/test')->load($testId);
if ($testModel->getId() || $testId == 0)
{
Mage::register('test_data', $testModel);
}
What this section of code does is 'registers' the selected model in Magento's registry. Later in the code, you'll see that it calls:
$form->setValues(Mage::registry('test_data')->getData());
to populate your form fields.
Try putting commands like these in the code above:
var_dump($testId);
die();
or
print_r($testModel);
die();
and running it again. Is $testId being set? Is $testModel being loaded? Is the if statement for the registry loading? If not, trace the problem back.
or it might also be
B) Your form is not prepopulating data because the column names are wrong.
Look where the code says:
<?php
class Pfay_Test_Block_Adminhtml_Test_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('test_form', array('legend'=>'ref information'));
$fieldset->addField('nom', 'text',
array(
'label' => 'Nom',
'class' => 'required-entry',
'required' => true,
'name' => 'nom',
)
);
You need to ensure that "nom" is in fact one of your model's attribute names. Did you change the attribute names when you created your test model and forgot to change it here? Change these values accordingly.
I hope that this helps you to solve your problem. Good luck!

Change template after user login in joomla 1.5

Anybody ever tried to change joomla 1.5 template in code? Don't know how to do it on current version. I just wanted to change the template after the user login.
So, i wrote code like this :
$mainframe->setTemplate('newtemplate');
But it doesn't works. WHen i see the joomla application.php, whoops, there is no setTemplate function there, but it used to be there before 1.5 (based on my search on the web).
Anyone know how to do it?
Update :
seems that we can set user state and just read that user state, then render. But I don't know where joomla render the template, since I put a code in library/joomla/application.php, insite render(), but it didn't get executed. This is what i did :
function render()
{
$params = array(
'template' => $this->getTemplate(),
'file' => 'index.php',
'directory' => JPATH_THEMES
);
// I added this code, where i set the user state $option.template somewhere else
$template = $mainframe->getUserState( "$option.template", 'FoxySales01VIP' );
if(!empty($template)){
$params['template'] = $template;
}
$document =& JFactory::getDocument();
$data = $document->render($this->getCfg('caching'), $params );
JResponse::setBody($data);
}
Never mind, i solved it.
Just change the code in core library (JDocument Class) to read the template from session, works fine.
Thanks

Resources