Ajax request in magento module - magento-1.5

I developing magneto module, In this module i want to make a ajax request in admin panel.I don't understand were to add script and controllers.please help me.
My requirement:
When change the select box(On change) i want add some field in the form.
Mycode:
/app/code/local/<Namespace>/<Module>/Block/Adminhtml/<Module>/Edit/Tab/Form.php
$fieldset->addField('type', 'select', array(
'label' => Mage::helper('<Module>')->__('Article Type'),
'name' => 'status',
'values' => array(
array(
'value' => '',
'label' => Mage::helper('<Module>')->__('Choose'),
),
array(
'value' => 1,
'label' => Mage::helper('<Module>')->__('Normal'),
),
array(
'value' => 2,
'label' => Mage::helper('<Module>')->__('video'),
),
),
'required' => true
));
I am creating fields using this.
How can i add another field on change.
Where should i add script
Where should i add controller
I created this module using this instructions

Let this field always be on the form. But make it invisible and show when you need it.
In the same template where the form is.
Place controller in your module. On stackoverflow you can find many questions about creating your own magento module and controller.

Related

magento multiselect product attribute not showing option labels on frontend

I have checked lot and tried many things, but I am still not getting the product multiselect selected values label on product view page.
I have product attribute called package which is multiselect,
Code that create the product attribute
$this->addAttribute(
'catalog_product',
'package',
array(
'group' => 'Package',
'backend' => 'eav/entity_attribute_backend_array',
'frontend' => '',
'class' => '',
'default' => '',
'label' => 'Package',
'input' => 'multiselect',
'type' => 'text',
'source' => 'npm_recurrex/package_source',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'is_visible' => 1,
'required' => 0,
'searchable' => 0,
'filterable' => 0,
'unique' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'user_defined' => 1,
)
);
this works fine, I am successfully saving the product.
But in frontend product view page when I say
Mage::log(print_r($_product->getData('package'), true));
Its prints the result as 1,2
But I wanted to display option labels of multiselect not option id's.
So I tried with this code
Mage::log(print_r($_product->getAttributeText('package'), true));
It prints nothing, just blank space :(.
I have checked this link but no use.
I am confused with this, Where I am wrong? and what is the wrong thing?
Can anybody explain me what is happening in my case?
If you need to show Drop Down or Multiple select value of an attribute product you should do something like this:
$attributes = $_product->getAttributes();
$customAttributeValue = $attributes['custom_attribute']->getFrontend()->getValue($_product);
Mage::log($customAttributeValue);

Select specific custom post type from selected taxonomy on wordpress

hello i have post_type "product" and taxonomy "price" can someone help me to query that custom post type with the selected taxonomy?
my current code is like this
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$args = array(
'post_type' => 'product',
'posts_per_page' => 5,
'tax_query' => array(
array(
'taxonomy' => 'productcategories',
'terms' => $term->name
)
)
);
query_posts($args);
print_r($args);?>
but nothing on result, can someone help me? thank you
i'm found what wrong already.
nothing wrong with the code, i'm already solved it. that's because i'm not set the content into selected custom category yet, that why it display null.
my bad

Wordpress custom post type archive page wp_query pagination not working

I have created an archive page for my 'Event' custom post ape called archive-event.php.
I used the content from the standard archive.php template and it listed my 4 events in the order they were posted.
The next step was to change the order by the custom field event_date. I did this no problems. Then I wanted to not show any events that event_date had passed. The below code does this perfectly.
The issue I now have is my pagination is all messed up. I have the default reading settings set to 2 posts per page and I have a 'Load more' button to bring up the next two.
When I click 'Load more' it duplicates the two events already showing. Any ideas where I've gone wrong?
<?php
$today = date("Ymd");
$args = array (
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'value' => $today,
'type' => 'numeric',
'compare' => '>=',
)
),
);
$wp_query = new WP_Query( $args );
while( $wp_query->have_posts() )
{
$wp_query->the_post();
?>
<div>Content goes here</div>
<?php } wp_reset_postdata(); ?>
Depending on how the plugin builds the UI it may or may not be respecting the pagination functionality built into WordPress.
Try forcing the paged setting into your query like so:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array (
'post_type' => 'event',
'paged' => $paged, // this will be set to what WordPress thinks is the proper page to start
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'value' => $today,
'type' => 'numeric',
'compare' => '>=',
)
),
);
Next, if this still doesn't work, you can test the assumption that the paged parameter isn't working for some reason by changing the default paged value like so (again, just to test):
$paged = 2; // just force it to start on the second page to see if that works
If the above test works, I would say that get_query_var() believes you're on the first page.

How do I add an Excerpt box to custom post types in functions?

I just want the standard Excerpt box - not a metabox of my own creation, added to a Custom Post. The box shows up in Posts but not in Custom Posts. I've tried both of these older solutions but neither of them worked (maybe it's a WP 3.9 problem):
The custom post type name is "Scoop"
I added this to the register_post_type_scoop() $labels = array
'supports' => array('title','thumbnail','excerpt')
but it didn't work - neither did this:
add_post_type_support('Scoop', 'title');
add_post_type_support('Scoop', array('title', 'thumbnail', 'excerpt') );
Add a index value excerpt to the supports object. Below the example is:
add_action( 'init', 'create_testimonial_posttype' );
function create_testimonial_posttype(){
register_post_type( 'testimonials',
array(
'labels' => array(
'name' => __( 'Testimonials' ),
'singular_name' => __( 'Testimonial' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'clients'),
'supports' => array('title','thumbnail','editor','page-attributes','excerpt'),
)
);
}

Using multiselect module in custom module (drupal 6)

Im programming my own module in Drupal 6 and create a form, but I need something to select data from a list. I am trying to use multiselect module. I can show the field with options, but on submit I cant get the selected options.
I made the following:
$element = array(
'#type' => 'field_multi_select',
'#title' => 'Field name',
'#description' => 'description',
'#multiple' => true,
'required' => true,
'#field_name' => 'field_select',
'#columns' => array('value'),
'#value' => array(array('value' => null)),
'#process' => array('multiselect_select_process'),
'#enable'=>true,
'module' => 'module name' // set here you current module name
);
$form['#field_info']['field_multi_select'] = $element;
$element = multiselect_select_process($element, NULL, $form_state, $form);

Resources