Why am I getting a page not found error after creating a new menu item? - drupal-6

In my module file I created a new menu item
function xmlproject_menu()
{
$items = array();
//more items here
$items['system/xml/cfa/initialize/%/%/%/%/%'] = array(
'page callback' => 'xmlproject_initialize_cf',
'page arguments' => array(4, 5, 6, 7, 8,),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function xmlproject_initialize_cf($session_id, $cart_id, $pid, $rid, $partner_id)
{
//some code here
}
I have tried going to admin/build/modules, devel/menu/reset, and admin/settings/performance to clear the cache. I can see the menu item in the database (menu_router).
When I go to http://example.com/system/xml/cfa/initialize/1/2/3/4/5 I am getting "Page not found".

You code seems all dandy, but I suppose your page callback "xmlproject_initialize_cf" should actually return something.
Try this:
function xmlproject_initialize_cf($session_id, $cart_id, $pid, $rid, $partner_id)
{
// Your Code
return 'Hello world!';
}
Is the modules name "xmlproject"?

Does not seems anything wrong with your code.
Just curious, why you have kept the last element of array as 'empty' (a comma after number 8)
'page arguments' => array(4, 5, 6, 7, 8,),
Also, there is additional empty item in the array (extra comma after MENU_CALLBACK)
'type' => MENU_CALLBACK,

As you see in your database number_part column that contains Number of parts in router path,sets to 7(maximum available part),but your parts of menu callback is 9.Which is more than MENU_MAX_PARTS available in drupal 6. this is why you're getting Page not found
Just reduce your menu item size and you are good to go.for example:
$items['initialize/%/%/%/%/%'] = array(
'page callback' => 'xmlproject_initialize_cf',
'page arguments' => array(4, 5, 6, 7, 8),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);

Related

Magento - custom product option don't show in order

I'm try to add custom option to product programmatically whyle add him to cart. I'm use:
$a_options = array(
'options' => array(
'label' => 'Glove Size',
'value' => $attr_value ,
)
);
$item->addOption(new Varien_Object(
array(
'product' => $item->getProduct(),
'code' => 'additional_options',
'value' => serialize($a_options)
)
));
$quote->addItem($item);
This is shows option for product in cart and during checkout process, but don't show option in order information.
I also tried:
$item->getProduct()->addCustomOption('additional_options', $attr_value );
Try to show them via attributes - didn't help.
$params = array('product' => '1919','qty' => 1,
'options' => array(
'glove_size' => $gloves_id,
),);
$cart->addProduct('1919', $params);
Magento version is 1.5
I haven't check that in 1.5 version but the below code will work in 1.7.2 version:
For viewing the custom options you need set options in order items.That can be done through by calling an event sales_convert_quote_item_to_order_item
<sales_convert_quote_item_to_order_item>
<observers>
<jrb_setcustomoption_observer>
<type>singleton</type>
<class>jrb_setcustomoption/observer</class>
<method>salesConvertQuoteItemToOrderItem</method>
</jrb_setcustomoption_observer>
</observers>
</sales_convert_quote_item_to_order_item>
Set the details options in your observer
public function salesConvertQuoteItemToOrderItem(Varien_Event_Observer $observer)
{
$quoteItem = $observer->getItem();
if ($additionalOptions = $quoteItem->getOptionByCode('additional_options')) {
$orderItem = $observer->getOrderItem();
$options = $orderItem->getProductOptions();
$options['additional_options'] = unserialize($additionalOptions->getValue());
$orderItem->setProductOptions($options);
}
}
For More details you can find in this article:
Magento - custom product option don't show in order
Thanks to Vinai

Infinitescroll to finish after a certain number of posts

I am using Paul Irish's infinitescroll with masonry js on a wordpress site. It is a site with a lot of content. I want infintescroll to stop adding new content when it reaches post number 40 and to give the "No additional items" message at that point. I tried to customize the wordpress loop to only return 40 posts but that did not seem to work.
I thought that maybe one of the options in infinitecroll might do the trick but the infintescroll documentation is very sparse. For example, there is an infinitescroll option in the "loading" init section called "finished: undefined" Is it possible to change that parameter to stop the scrolling after a certain number of content items?
Is there some other obvious way to control when infinitescroll stops loading new content?
Any assistance would be greatly appreciated.
In the Administration -> Settings -> Reading you can set Blog pages show at most to 40.
With code:
Two ways I've done Masonry by numbers like your question I've had success with the following:
limit posts_per_page in your query arguments
$args = array(
'posts_per_page' => 40,
'offset' => 5,
'orderby' => 'post_date',
'order' => 'DESC',
'exclude' => 'none',
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts = new WP_Query( $args );
if ( $posts -> have_posts()) {
while ( $posts -> have_posts() ) : $posts->the_post(); {
//do stuff with the posts returned here
}
}
or by incrementing:
$counts = 0 ;
$posts = new WP_Query( $args );
if ( $posts -> have_posts()) {
while ( $posts -> have_posts() ) : $posts->the_post(); {
//do stuff with the posts returned here
$counts = ++;
if($counts == 40) { return }
}
}

Changes in module_menu() aren't applying

I have a custom module called tf_partner. I just modified this to include another argument. Inside the module I have:
function tf_partner_menu()
{
//... more code.....
$items['partner/letters/word/replace/%/%/%/%'] = array(
'page callback' => 'tf_partner_replace_image',
'access callback' => TRUE,
'page arguments' => array(4, 5, 6, 7),
'type' => MENU_CALLBACK,
'file' => 'tf_partner_letters.inc.php',
);
//...more code
}
This is what it used to be ...
function tf_partner_menu()
{
//... more code.....
$items['partner/letters/word/replace/%/%/%'] = array(
'page callback' => 'tf_partner_replace_image',
'access callback' => TRUE,
'page arguments' => array(4, 5, 6),
'type' => MENU_CALLBACK,
'file' => 'tf_partner_letters.inc.php',
);
//...more code
}
function tf_partner_replace_image($aid, $letter, $position, $randstr)
{
echo "here"; //doesn't show up
}
The problem is when I try to go to the new url, it doesn't work and goes to /partner/letters/word. I already went to admin/build/modules, but still getting the problem. I checked the database (menu_router table) and it looks correct.
EDIT: Also, I created a new function similar to this and a new menu item. I started with 1 argument and added one at a time. It allowed me up to 3. When I added the 4th one, it didn't work anymore.
clear cache on admin/settings/performance
or by emptying cache_{name} tables in database.
code looks fine, I guess menu just didn't get rebuilt.

Pass arguments to a view in Drupal 6 via custom module

I'm using Drupal 6 to run a gallery I've created. I need to take a parameter from the AJAX request lets say "food" and pass that argument to a view I've created (Views 2) where "food" is a taxonomy term that I am using to get the data I want in return. Everything is working just fine and in my module's method for loading the view I can load the entire view because in the settings you have 'if no argument get all values', but I can't seem to pass arguments to it. Here is the method...
function ajax_methods_menu()
{
$items = array();
$items['admin/settings/ajax_methods'] = array(
'title' => t('AJAX Methods settings.'),
'description' => t('Define settings for the AJAX Methods'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_methods_admin'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM
);
$items['gateway'] = array(
'title' => 'AJAX Gateway',
'page callback' => 'ajax_methods_get_items',
'type' => MENU_CALLBACK,
'access arguments' => array('access content')
);
return $items;
}
function ajax_methods_get_items($args)
{
$content = views_get_view('All_Images');
return drupal_json(array('status' => 0, 'data' => $content->preview('default')));
exit;
}
In looking at the documentation views_get_view() doesn't seem to allow for arguments although I believe they are being passed to my ajax_methods_get_items() method. Thanks for reading!
Got it figured out, I needed to add
return arg(1);
seems to be working pretty well.

Drupal Profile alter: hook_form_alter

After reviewing some posts here and elsewhere, I still can't seem to manually add a select field to the profile. (I need the select list to be populated with a SQL query, not supported with core profile module.)
So far, I am trying two different ways: hook form alter ($form_id == 'user-register' & hook user ($op == 'register') -- but I can't even get the field to appear in the registration form.
function accountselect_user($op, &$edit, &$account, $category = NULL) {
if ($op == 'register'){
$fields['account_select'] = array(
'#type' => 'fieldset',
'#title' => t('Your Security Question')
);
$fields['account_select']['account_name'] = array(
'#type' => 'select',
'#default_value' => 'Select',
'#description' => t('Select a verification question in case you forget your password'),
'#options' => array(t('Select One'),
t('Where you attended Elementry School'), t('Your Best Man'))
);
return $fields;
}
Here is the hook form alter attempt
function accountselect_form_alter(&$form, $form_state, $form_id){
if($form_id == 'user-register') {
$form['account_select']['account_name'] = array(
'#type' => 'select',
'#title' => t('Account'),
'#description' => t('Enter the account to which the contact belongs.'),
'#options' => array(t('Account1'),t('account2'), t('account3')),
'#default_value' => $edit ['Account']
);
}
return $fields;
}
Sorry Guys, the code here is correct. I did a little debugging when the module was first enabled. I thought I had successfully fixed the problem, but what really happened is that the module became disabled. So, no matter what was in there, it would have had no effect....
No worries, I've punched myself in the face for the stupid question....

Resources