Posted by zkrebs on August 17, 2010 at 5:18am
This is a place for Q&A in S. Oregon Drupal Community. There does not appear to be a forum feature available (afaik), so this can be used.
Would love to help anyone figure out anything Drupal related.

Comments
My own Q
I need to do a site that will have 4 different layouts. Each layout will have a different background. I am investigating the options for this, and I am attempting to find one that is simple. Any ideas?
Seems like Context is great for placing blocks/views/stuff for different pages, but it assumes the layout that the theme provides. What if the layout needs to change for each context? The context layout module seems to only let you specify one CSS file per layout. Maybe this will work, but it seems less supported.
Panels seems to let you define layouts. Appears as though I could create custom layouts like here: http://drupal.org/node/495654 so I could make a node-panel page and choose the layout, linking the page to the menu. Put blocks/content/views into regions in PanelsUI and call it good. This might be easiest for the client?
Panels Everywhere...no idea, but this seems to be like Context?
Then, there's Node Display Suite. That seems to be able configuring the layout of the content of nodes. I'm sure that could factor in.
But, my question is, whats the best way to switch the layout/css for different "pages" without using a billion modules?
It depends how different the
It depends how different the layouts are going to be. If the layout variations can be done with css I would use css_injector to override the styles. Context does work well with css_injector so you can define the blocks and styles for the different areas of your site.
Panels is a powerful module, but in my use cases it tends to be a bit more than is needed for most situations. Endusers also can be easily confused with the panels interface.
hozt
The CSS seems to be a good idea, but I am really looking for a way to change the layout significantly for each page - especially something that is aware of the 960 grid system. I will try a site with css_injector and see if that float my boat :) Have you ever used http://drupal.org/project/themekey ?
I have not tried themekey,
I have not tried themekey, but may use in at some point in the future.
It would be interesting to see what you are working on.
Hozt
Its really nothing complex - its just a photoshop design-oriented page where the designer wants different kinds of layouts for every page. Sometimes I think just using html/css would be easier, and not using Drupal. However, there's power in using the framework, so that is the choice.
I have decided to use Panels on top of the Fusion Theme, but modified to use a 24 column grid. This way, each page can have a custom layout. Then if you click on the settings of a panels region and/or pane, you can specify grid dimensions as the css class ( grid-12 , grid-12 for a 50/50 split). Save the layouts so they are re-usable. Then, theme the node.tpl for whatever purposes.
Hope that helps you imagine what I'm doing.
Hozt
I saw some bug reports on the GitHub for Barracuda - how is that going for you? I am really loving it, but there are some things that I need to learn how to do with Nginx still.
Also, I tried out CSS Injector and it works very nicely! Thanks for the heads up. Also, as a note, it works well with Pressflow, in case anyone cares.
I am running Barracuda for
I am running Barracuda for most of my sites now. There has been a bit of a learning curve with using Nginx. The only issue I am having involves uploading large files. I can not get FileField Nginx Progress to work as it should.
Another very cool alternative to css_injector that I am testing is: http://drupal.org/project/sweaver
hozt
Thanks for the sweaver thing. I've been ssh'ing and using nano to edit CSS files, and using Firebug or Chrome's debugger to make CSS changes. Sweaver is indeed cool, thanks for the heads up.
Do you use Boost on your sites with Barracuda? I tried it on one, and its directory permissions rules did not seem to work with Boost, or perhaps I just mis configured.
Yes, I have been using
Yes, I have been using boost.
As for Barracuda, I am most likely going to transition back to using apache with pressflow. I am much more comfortable with using apache and there is more support for it than nginx. I also like having a bit more control of the upgrade process.
Hey
OK, that's interesting to hear. It was nice running into you at the Coop with my girlfriends kids before - aren't they great? Good luck with your projects.
Views Customfield
http://drupal.org/node/467190#comment-3731096
Hozt or Joe, could you look at this request? Working with ubercart adjustment SKU's with stock levels/pricings and showing them in a view is totally stumping me.
What if you set the view to
What if you set the view to output as a node type and then create a theme override the node probably using node-product.tpl.php. Then you could have full control of how each product is displayed.
Hozt
thanks for the suggestion, I ended up doing this because your suggestion, while valid, would have required a rewrite of the way the site was working:
http://drupal.org/node/467190#comment-3742764
Found this to be useful: http://www.ubercart.org/forum/support/4037/stock_level_product_page
But, ended up using the uc_views module, added stock as a field (hidden). Added custom views field of:
<?phpIF ($data->uc_product_stock_stock > 0) {
print "In Stock";
}
ELSE {
print "Out of stock";
}
?>
Then, I used the viewsfield module to make the view a CCK field on my product page, passing the NID as an argument.
Used Display Suite to show the field in the right spot.
PHP ?
For a store that needs to show a list of products, by attribute that are IN Stock I have found no solution other than making a node page with PHP display filter (below). However, I would like to add a clickable URL into the results, that goes to the node page. Any helpful hints?
<?php
$header = array('Rose','Link');
$rows = array();
$sql = "SELECT DISTINCT n.titleFROM uc_product_adjustments upa
JOIN uc_product_options upo on upa.nid=upo.nid
JOIN uc_product_stock ups on upa.model= ups.sku
JOIN node n on n.nid = upa.nid
where upa.nid = upo.nid and upa.combination like '%3%' and ups.stock > '0' ORDER BY title";
$res = db_query($sql);
while ($row = db_fetch_array($res)) {
$rows[] = $row;
}
print theme('table', $header, $rows);
?>
I'm probably missing
I'm probably missing something because this seems too obvious, but If I understand your SQL correctly you are fetching a single field 'title'. Can you also get the 'nid' while you're at it, then use that to build an array of <a> tags? Something along the lines of:
while ($row = db_fetch_array($res))
{
$rows[] = "<a href="'/domain/node/".$row[nid]"'>".$row['title']."
}
print theme('table', $header, $rows);
let me test it a bit more and get back to you
i think i got it
In case anyone is interested
This turned out to be simple....
<?php
$sql = db_query("
SELECT DISTINCT n.title, n.nid
FROM uc_product_adjustments upa
INNER JOIN uc_product_options upo
on upa.nid=upo.nid
INNER JOIN uc_product_stock ups
on upa.model= ups.sku
INNER JOIN node n on n.nid = upa.nid
where upa.nid = upo.nid
and upa.combination like '%3%'
and ups.stock > '0' ORDER BY title");
$rows = array();
while ($row = db_fetch_object($sql)) {
$rows[] = array(
array('data' => l($row->title, 'node/'. $row->nid)),
);
}
$header = array(
array('data' => 'Rose Name'),
);
print theme_table($header, $rows);
?>
uc_fee not working with attributes
Anyone here willing to help tackle this issue? Hozt, I called you about something a day or two ago too.
http://drupal.org/node/891508
In sum, the issue is UC_FEE adds a fee for each item in the cart, even if you're telling it to add by SKU or product attribute, resulting in potentially huge fees! And no, adding the fee to the product option price is not a solution for every use-case.
I believe in the uc_fee.module code, this is the offending section:
* Calculates the fees for an order based on enabled fee modules.
*
* @param $order
* The full order object for the order want to calculate fees for.
* @return
* An array of fees for the order.
*/
function uc_fee_calculate($order) {
// Find any fees specified by enabled modules.
$fees = module_invoke_all('calculate_fees', $order);
return $fees;
}
/
* Calculate the amount and types of fees that apply to an order.
*/
function uc_fee_calculate_fees($order) {
global $user;
if (is_numeric($order)) {
$order = uc_order_load($order);
$account = user_load(array('uid' => $order->uid));
}
elseif ((int)$order->uid) {
$account = user_load(array('uid' => intval($order->uid)));
}
else {
$account = $user;
}
if (!is_object($order)) {
return array();
}
if (is_array($order->line_items)) {
foreach ($order->line_items as $i => $line) {
if (substr($line['type'], 0, 4) == 'fee_') {
unset($order->line_items[$i]);
}
}
}
$apply_fees = array();
$applied_exclusive = FALSE;
$fees = uc_fee_get_fees();
$order->fees = array();
$arguments = array(
'order' => array(
'#entity' => 'uc_order',
'#title' => t('Order'),
'#data' => $order,
),
'fee' => array(
'#entity' => 'fee',
'#title' => t('Fee'),
// #data => each $fee in the following foreach() loop;
),
'account' => array(
'#entity' => 'user',
'#title' => t('User'),
'#data' => $account,
),
);
foreach ($fees as $fee) {
// skip fees which may not be applied with other fees
if ($fee->is_exclusive && !empty($apply_fees)) {
continue;
}
$arguments['fee']['#data'] = $fee;
$predicates = ca_load_trigger_predicates('calculate_fees');
if (ca_evaluate_conditions($predicates['uc_fee_'. $fee->fid], $arguments)) {
$line_item = uc_fee_action_apply_fee($order, $fee);
if ($line_item) {
$order->fees[$line_item->id] = $line_item;
// keep a record of which fees we have applied
$apply_fees[$fee->fid] = array(
'description' => check_plain($fee->description),
'amount' => $line_item->amount,
);
// we have just applied an exclusive fee, or one which requests that we stop processing
if ($fee->is_exclusive || $fee->do_end_processing) {
break;
}
}
}
}
return $order->fees;
}
Can we figure this out?
EDIT: Client just added the fee to the attribute price and changed the attribute title to "Size (includes $8.00 fee)": $realprice
Seems to work..but hey, we could still fix uc_fee ;)
Ubercart Kits and such
I have a client who needs to sell software and software maintenance (2 products)
If a customer buys 1-4 of the software, they need to be charged for 5 maintenance licenses.
If a customer buys 5+ of the software, they buy the same amount of maintenance licenses (5/5 6/6 100/100, etc.)
If I use a product kit, it will add each product to the cart ,with a quantity. That works for orders in surplus of 5, but what about orders for 1-4 licenses?
I want to avoid the user having to manually update their cart with the correct numbers.
Thanks.
OK
Here's some cool code for D6. on your node-type.tpl.php add
<pre><?php print print_r($node, TRUE); ?>
</pre>
To see all the available fields for that node type. Then, you can add CCK fields to content type and theme them!
I wanted to add a reference to a view link, so at the top of my node-type.tpl.php I added
<?php$relatedPath = $node->field_relatedview[0]['url'];
?>
The related view just held a path such as "/view/argument"
Then in my template I themed the output
<div class="buybutton"><a href="<?php print $GLOBALS['base_url'] ?>/<?php print $relatedPath; ?>"><img src="http://site.com/images/cms/clickheretopurchase.png" alt="Click here to purchase <?php print $node->title; ?>" /></a></div>Probably simple boring stuff no one cares about..but hey!
The Devel module is great for
The Devel module is great for showing the fields. Once enabled you will have a tab next to the Edit one that will allow you to view all the variables. If you are in the code and have devel enabled use this for a formatted view of the array.
dpm($node);Another great way to see the fields is to use the Contentplate module. This allows you to very easily override the output of your content. It is better to do this with a theme tpl file, but for a quick and dirty override it works well. I will often enable this when working with a custom tpl file to see the exact field names. I can just cut and paste them into my tpl.
Good Stuff!
Thanks!
Oh yeah, the devel module, better get going on that now that Im tinkering with php code;
By the way, I was using the Link module -
I was wondering if there was a view reference cck field that just LINKED to a view page, but did not show the view page.
I saw this: http://drupal.org/project/viewreference
Defines a field type View reference which creates a relationship to a Views display and allows the view to be displayed as the content of the field.
This module is modelled on Node reference and usage is similar.
Additionally, you may enter arguments for each view by a delimiter seperated list with support for PHP generated arguments.
And I saw this: http://drupal.org/project/nodereference_views
This module provides a new display formatter for CCK node reference fields. The formatter allows a view to be used as the display style for CCK node reference fields. This means that instead of just a title, teaser, or full node, you can show nodes using any fields that are available to Views, in any sort order, in any view style, with any views theming.Both let you show a view on a node, or use a node as a view, but what I wanted was simply a way to link a node to a view display page through a module.
Seemed like link was the choice. But on second thought, I could use the same method I described as above, with a text field. Hindsight is 20/20 though :D
php question
Hi, sorry about my dot tpl joke. That was just my strange sense of humor. I have been experimenting with Omega subthemes. I'll try to resist my attempts at humor.
I do have a question? Regarding the php $GLOBALS. From my work with php and php.ini the default is to turn register_globals off. Since php 4.2.0 that is the recommended default for security reasons. They provide superglobals including $_SERVER['SERVER_NAME'] which provides the www.yourdomain.xxx and $_SERVER['DOCUMENT_ROOT'] which indicates the current document path that is running the php script. There is also $_SERVER['PATH_INFO'] and other superglobals. I haven't reviewed the the template code you showed but I suspect the use of $GLOBALS may not be recommended. Checkout php.net to read about the security issue with register_globals in php.ini. That is also currently depreciated in php 5 and up. I haven't looked at php in Drupal to any significant degree but my guess is the code is written according the the current standards shown in php.net?
D6
I'm still trying to understand what you mean by D6? I remember some long past reference to D6 but forgot what it meant. Is dot tpl something Drupal people do on Friday nights? Just kidding. Based on Jeff's recommendation I'm trying the Omega Theme and it is very interesting. Well worth learning. You are also trying to get us to play in the php sandbox too. And some of this is not simple and boring to me at least! Keep up the great comments. I'm excited to be part of a group that shares information. When you plant seeds you never know what flowers might bloom.
Hey Bill
D6 is Drupal 6, D7 is Drupal 7. Just shorthand stuff.
If you investigate your themes folder in /sites/all/themes you'll likely see a node.tpl.php. This is general layout file for all of your nodes on your site. If you use CCK or Custom Content Types, you can then create node-CUSTOM.tpl.php to make custom layouts for that page. If you're familiar with PHP and like doing code, then its one way of doing layouts and design vs. using a module like panels.
While we're on the topic
I used the Node Displays module to do layouts of CCK fields on one site, it worked really well, without any coding! Its kind of like context/panels, but for just the node layout itself.
http://drupal.org/project/nd for D6 and http://drupal.org/project/ds for D7
I have not used display suite
I have not used display suite before today, but it solved a problem with a custom display that I had setup today. Thanks for the recommendation!