Jump to content

versatilewt

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://www.versatilewt.com

Profile Information

  • Gender
    Not Telling

versatilewt's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks ChemicalBliss, The only thing is, I'm trying to have a generic class that can handle the simple cases and the variable case, and get the sub template out of the db if it's needed - and essentially examine the "replacements" array to see if it's necessary. I was kind of envisioning passing something like: array( '%customer_name%'=>'Bob', '%website_name%'=>'Acme', '%products%' = array( '0'=>array('%product_name%'=>'WidgetA', '%product_price%'=>'$1'), '1'=>array('%product_name%'=>'WidgetB', '%product_price%'=>'$2'), '2'=>array('%product_name%'=>'WidgetC', '%product_price%'=>'$3'), ) );
  2. Hi all, So I'm setting up a system that has a lot of emails, and variable replacement within it, so I'm writing a class to manage some variable replacement for templates stored in the database. Here's a brief example: // template is stored in db, so that's how this would get loaded in $template = "Hello, %customer_name%, thank you for contacting %website_name%"; // The array of replacements is built manually and passed to the class // with actual values being called from db $replacements = array('%customer_name%'=>'Bob', '%website_name%'=>'Acme'); $rendered = str_replace(array_keys($replacements), $replacements, $template); Now, that works well and good for single var replacements, basic stuff. However, there are some places where there should be a for loop, and I'm lost how to implement it. The idea is there'd be a template like this: Where, {products} would be an array passed to the template, which the is looped over for products requested, with a format like: So an example rendered version of this would be: What's the best way to accomplish this?
  3. I'm programming an application to automate business processes for a company. The system has a lot of notifications required, and I'm trying to think of the best way to set up the notification system. For example, when a customer replies to an email, it gets piped into the system and a sales rep gets an email. When a customer pays, a notification gets sent to the sales rep, the manager, and the vp of the divison. When an order ships, a notification gets sent to the sales rep, the manager, and the fulfillment department. So, my thought is to make a rules table, with the name of the rule for people that get notified in addition to the sales rep. Then, have a n:m table for users to rules, and when a notification should happen, look up the rule name in the db, find who gets notified, and send out the notifications. One thing I'm having an issue with is, how would I make a rule that references the particular sales rep (i.e. I'd make a rule to notify sales rep, but that sales rep would be different on every account - the n:m table for rules->users couldn't directly link to the actual sales rep, i'd have to be like a variable or something) I'm trying to keep this flexible for future considerations of rule changes (say the vp wants to stop getting copied on certain status updates). Any advice on the best way to go about something like this?
  4. So, basically I need to list multiple orders on a page, along with their line items. There is an orders table, and a line items table - basic set up. This is the way I'm doing it now, and I'm wondering if there's not a more efficient way to do this. I've simplified the code a bit for my question here, but it gets the point across $order = $db->getAssoc(SELECT * FROM orders); foreach($order as $k=>$v) { $line_item = $db->getAssoc("SELECT * FROM order_line_item WHERE order_id = $k"); $order[$k]['shipping'] = $line_item; } And then I just operate on the order array to get the info. Is there a better way to do this?
  5. Here's what I'm trying to do Right now I have a bunch of "template" email responses stored in my DB, which are used frequently. Basically, what I'd like to do is for the templates, store things like ##CUSTOMER_NAME## and ##PRODUCT_NAME## in them. Then, when emailing, I'd like to pass an array of data (like, array("CUSTOMER_NAME"=>"Bob, "PRODUCT_NAME"=>"Widget") or whatever, depending on the particular email. There are also some basic if statements I want to execute, like if ##STATE## of customer == my state, say we'll charge you sales tax, or if ##STATE## in_array("CA", "WA", "OR") say "west coast" or something. I'm guessing it would involve preg_replace and some for loops, but I'm not sure the most efficient way to go about this. Any advice/suggestions appreciated. Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.