php-general Digest 31 Dec 2012 08:31:53 -0000 Issue 8080

2012-12-31 Thread php-general-digest-help

php-general Digest 31 Dec 2012 08:31:53 - Issue 8080

Topics (messages 319973 through 319974):

Re: how to build multilingual e-commerce website
319973 by: Sachin Raut

Shopping Cart Discount System
319974 by: Karl DeSaulniers

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Thanks all for your suggestions. I have decided to go through these 2 books
 i will also talk to Magento developers.

Once again thanks for your input

regards
Sachin Raut

On Sat, Dec 29, 2012 at 9:20 AM, tamouse mailing lists 
tamouse.li...@gmail.com wrote:

  On Fri, Dec 28, 2012 at 5:19 AM, Sachin Raut imsachinr...@gmail.com
 wrote:
  Dear Friends,
 
  I have to develop multilingual e-commerce (clothing) website. Could
 anyone
  who has developed these kind of sites before guide me on how to start the
  development or recommend any tutorial / book for developing these kind of
  sites?
 
  Would really appreciate any inut regarding this.
 
  regards
  Sachin Raut


 There's this at O'Reilly: Building eCommerce Applications
 http://shop.oreilly.com/product/0636920023098.do

 And this at Amazon: Effortless E-Commerce with PHP and MySQL by
 Larry Ullman http://amzn.com/0321656229

 Also, not really knowing how much you need to do yourself, you could
 probably get a leg up using existing frameworks and such.

 The multilingual aspects will certainly be tricky. Gettext is sort of
 the standard for doing multilingual things, but in and of itself
 doesn't really provide much help in understanding *how* to do
 multilingual right, and can be problematic. Some frameworks do support
 multilingual sites; I know drupal does, for example, and includes
 quite a lot of other things that can help you build an e-commerce site
 rather quickly, but drupal itself has a rather steep learning curve.

 Passages of just plain text aren't that difficult; it's when you start
 constructing displayed text dynamically that it will be trickier, for
 certain.

 Just thinking off the top of my head; you will likely need something
 other than just gettext with it's separate language files for things
 like product descriptions. I think it gets rather difficult, and
 probably bad form, to have your separate strings in files in your code
 base linked to data base entries; simpler just to store the various
 multilingual data base bits in the data base itself. But you can see
 how complex it gets.

 At any rate, I hope you have a fair bit of experience in building
 dynamic internet sites already, this is not going to be easy.

---End Message---
---BeginMessage---

Hello Everyone,
Hope all are well. Quick and hopefully painless question.
Is there any examples on how to build a discount system
into your shopping cart out there that anyone knows of?
I am using MySQL and PHP. I have built one of my own so far,
but am having trouble making sense of what goes where.

For example. If a product has miscellaneous charges,
lets say.. glitter is extra on your shirt.
How is discounts applied? I mean, as far as discounts go,
lets say its 20% a shirt and this shirt has glitter.
Is it best practice to apply the discount to just the shirt
or the shirt and glitter as a combo discount.
I know this is somewhat dependent on the owners choice
of what he/she wants to give the discount on,
but my question is of the programing of it.
Do I build conditions for the shirt to get a discount applied
then the miscellaneous charges, or combine the totals of the two,
then apply the discount to the sum?

Then lets say there is a cart discount also being applied.
Is it best practice to apply this to the total of items then
add the shipping, rush charges and tax, or to the total of the whole  
cart
including shipping, rush charges then add the tax after applying the  
discount?


Sorry for the run-on question, hope this makes sense enough to merit  
help.


HNY,

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com

PS: Because this question could be answered by either database or  
general, is the only reason for the double post.

Wont be making a habit of it.. :)---End Message---


php-general Digest 31 Dec 2012 20:37:29 -0000 Issue 8081

2012-12-31 Thread php-general-digest-help

php-general Digest 31 Dec 2012 20:37:29 - Issue 8081

Topics (messages 319975 through 319981):

Re: Shopping Cart Discount System
319975 by: Ashley Sheridan

variable placeholders in a text file
319976 by: Nelson Green
319977 by: Stephen
319978 by: Ashley Sheridan
319979 by: Stuart Dallas
319980 by: Nelson Green
319981 by: Nelson Green

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---


Karl DeSaulniers k...@designdrumm.com wrote:

Hello Everyone,
Hope all are well. Quick and hopefully painless question.
Is there any examples on how to build a discount system
into your shopping cart out there that anyone knows of?
I am using MySQL and PHP. I have built one of my own so far,
but am having trouble making sense of what goes where.

For example. If a product has miscellaneous charges,
lets say.. glitter is extra on your shirt.
How is discounts applied? I mean, as far as discounts go,
lets say its 20% a shirt and this shirt has glitter.
Is it best practice to apply the discount to just the shirt
or the shirt and glitter as a combo discount.
I know this is somewhat dependent on the owners choice
of what he/she wants to give the discount on,
but my question is of the programing of it.
Do I build conditions for the shirt to get a discount applied
then the miscellaneous charges, or combine the totals of the two,
then apply the discount to the sum?

Then lets say there is a cart discount also being applied.
Is it best practice to apply this to the total of items then
add the shipping, rush charges and tax, or to the total of the whole  
cart
including shipping, rush charges then add the tax after applying the  
discount?

Sorry for the run-on question, hope this makes sense enough to merit  
help.

HNY,

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com

PS: Because this question could be answered by either database or  
general, is the only reason for the double post.
Wont be making a habit of it.. :)

I would apply the discounts where they made sense from a customer POV. Would 
you expect a t-shirt discount to be applied to only the base item or the 
product as a whole? I'd say tge whole thing. You could have various areas in 
your code that apply discounts at different levels: per item, per group of 
items (bogof, etc), and per basket.


Thanks,
Ash
http://www.ashleysheridan.co.uk
---End Message---
---BeginMessage---

Hello,

I have created a simple function that prints a personalized greeting by reading
the greeting contents from a file. I pass the user's name to the function,
and the function reads the file contents into a string variable. I am then
using str_replace to replace the word USER in the string with the user's
name that was passed to the function. Then the function correctly prints
the personalized greeting as I wish.

My question is, is there another way to do something similar, such as
embedding a variable name directly into the text file? In other words,
instead of my text file reading:

Hello USER ...

Can I do something like this:

Hello $user_name ...

and then write my function to replace $user_name with the passed
parameter prior to printing?

The reason I ask is because I am going to want to do three substitutions,
and I'd rather not do three str_replace calls if I don't have to. Plus the
latter seems to be a more robust way of making the changes.

Thanks, and apologies if this has been asked before and I missed it. I'm
just not sure how to phrase this for a search engine.

Nelson---End Message---
---BeginMessage---

Yes!

Easy standard stuff.

$title = 'Mr.;
$user_name = 'John Doe';

$message = Hello $title $user_name 

Just define the value for the variables before defining the value for 
the message.


Note that $message has to use double quotes for the expansion. Also 
consider using HEREDOC instead of the double quotes.


You may want to put your message in a text file and using the include 
function.


On 12-12-31 02:39 PM, Nelson Green wrote:

Hello,

I have created a simple function that prints a personalized greeting by reading
the greeting contents from a file. I pass the user's name to the function,
and the function reads the file contents into a string variable. I am then
using str_replace to replace the word USER in the string with the user's
name that was passed to the function. Then the function correctly prints
the personalized greeting as I wish.

My question is, is there another way to do something similar, such as
embedding a variable name directly into the text file? In other words,
instead of my text file reading:

Hello USER ...

Can I do something like this:


Re: [PHP] Shopping Cart Discount System

2012-12-31 Thread Ashley Sheridan


Karl DeSaulniers k...@designdrumm.com wrote:

Hello Everyone,
Hope all are well. Quick and hopefully painless question.
Is there any examples on how to build a discount system
into your shopping cart out there that anyone knows of?
I am using MySQL and PHP. I have built one of my own so far,
but am having trouble making sense of what goes where.

For example. If a product has miscellaneous charges,
lets say.. glitter is extra on your shirt.
How is discounts applied? I mean, as far as discounts go,
lets say its 20% a shirt and this shirt has glitter.
Is it best practice to apply the discount to just the shirt
or the shirt and glitter as a combo discount.
I know this is somewhat dependent on the owners choice
of what he/she wants to give the discount on,
but my question is of the programing of it.
Do I build conditions for the shirt to get a discount applied
then the miscellaneous charges, or combine the totals of the two,
then apply the discount to the sum?

Then lets say there is a cart discount also being applied.
Is it best practice to apply this to the total of items then
add the shipping, rush charges and tax, or to the total of the whole  
cart
including shipping, rush charges then add the tax after applying the  
discount?

Sorry for the run-on question, hope this makes sense enough to merit  
help.

HNY,

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com

PS: Because this question could be answered by either database or  
general, is the only reason for the double post.
Wont be making a habit of it.. :)

I would apply the discounts where they made sense from a customer POV. Would 
you expect a t-shirt discount to be applied to only the base item or the 
product as a whole? I'd say tge whole thing. You could have various areas in 
your code that apply discounts at different levels: per item, per group of 
items (bogof, etc), and per basket.


Thanks,
Ash
http://www.ashleysheridan.co.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] variable placeholders in a text file

2012-12-31 Thread Nelson Green

Hello,

I have created a simple function that prints a personalized greeting by reading
the greeting contents from a file. I pass the user's name to the function,
and the function reads the file contents into a string variable. I am then
using str_replace to replace the word USER in the string with the user's
name that was passed to the function. Then the function correctly prints
the personalized greeting as I wish.

My question is, is there another way to do something similar, such as
embedding a variable name directly into the text file? In other words,
instead of my text file reading:

Hello USER ...

Can I do something like this:

Hello $user_name ...

and then write my function to replace $user_name with the passed
parameter prior to printing?

The reason I ask is because I am going to want to do three substitutions,
and I'd rather not do three str_replace calls if I don't have to. Plus the
latter seems to be a more robust way of making the changes.

Thanks, and apologies if this has been asked before and I missed it. I'm
just not sure how to phrase this for a search engine.

Nelson

Re: [PHP] variable placeholders in a text file

2012-12-31 Thread Stephen

Yes!

Easy standard stuff.

$title = 'Mr.;
$user_name = 'John Doe';

$message = Hello $title $user_name 

Just define the value for the variables before defining the value for 
the message.


Note that $message has to use double quotes for the expansion. Also 
consider using HEREDOC instead of the double quotes.


You may want to put your message in a text file and using the include 
function.


On 12-12-31 02:39 PM, Nelson Green wrote:

Hello,

I have created a simple function that prints a personalized greeting by reading
the greeting contents from a file. I pass the user's name to the function,
and the function reads the file contents into a string variable. I am then
using str_replace to replace the word USER in the string with the user's
name that was passed to the function. Then the function correctly prints
the personalized greeting as I wish.

My question is, is there another way to do something similar, such as
embedding a variable name directly into the text file? In other words,
instead of my text file reading:

Hello USER ...

Can I do something like this:

Hello $user_name ...

and then write my function to replace $user_name with the passed
parameter prior to printing?

The reason I ask is because I am going to want to do three substitutions,
and I'd rather not do three str_replace calls if I don't have to. Plus the
latter seems to be a more robust way of making the changes.

Thanks, and apologies if this has been asked before and I missed it. I'm
just not sure how to phrase this for a search engine.

Nelson  



--
Stephen


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variable placeholders in a text file

2012-12-31 Thread Ashley Sheridan
On Mon, 2012-12-31 at 13:39 -0600, Nelson Green wrote:

 Hello,
 
 I have created a simple function that prints a personalized greeting by 
 reading
 the greeting contents from a file. I pass the user's name to the function,
 and the function reads the file contents into a string variable. I am then
 using str_replace to replace the word USER in the string with the user's
 name that was passed to the function. Then the function correctly prints
 the personalized greeting as I wish.
 
 My question is, is there another way to do something similar, such as
 embedding a variable name directly into the text file? In other words,
 instead of my text file reading:
 
 Hello USER ...
 
 Can I do something like this:
 
 Hello $user_name ...
 
 and then write my function to replace $user_name with the passed
 parameter prior to printing?
 
 The reason I ask is because I am going to want to do three substitutions,
 and I'd rather not do three str_replace calls if I don't have to. Plus the
 latter seems to be a more robust way of making the changes.
 
 Thanks, and apologies if this has been asked before and I missed it. I'm
 just not sure how to phrase this for a search engine.
 
 Nelson  


You could use an existing templating solution, like Smarty, although for
what you want to do it might be overkill. A few str_replace() calls
shouldn't produce too much overhead, but it depends on the size of the
text string in question. If it's just a couple of paragraphs of text, no
problem, something closer to a whole chapter of a book will obviously be
more expensive.

You could try eval() on the block of text, but if you do, be really
careful about what text you're using. I wouldn't recommend this if
you're using any text supplied by a user. As a last option, you could
have the text stored as separate parts which you join together in one
string later. This might be less expensive in terms of processing power
required, but it also makes maintenance more of a hassle later.


Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] variable placeholders in a text file

2012-12-31 Thread Stuart Dallas
Please excuse the top post, but this may be helpful: 
http://stut.net/2008/10/28/snippet-simple-templates-with-php/

-Stuart

-- 
Sent from my leaf blower

On 31 Dec 2012, at 19:59, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 On Mon, 2012-12-31 at 13:39 -0600, Nelson Green wrote:
 
 Hello,
 
 I have created a simple function that prints a personalized greeting by 
 reading
 the greeting contents from a file. I pass the user's name to the function,
 and the function reads the file contents into a string variable. I am then
 using str_replace to replace the word USER in the string with the user's
 name that was passed to the function. Then the function correctly prints
 the personalized greeting as I wish.
 
 My question is, is there another way to do something similar, such as
 embedding a variable name directly into the text file? In other words,
 instead of my text file reading:
 
 Hello USER ...
 
 Can I do something like this:
 
 Hello $user_name ...
 
 and then write my function to replace $user_name with the passed
 parameter prior to printing?
 
 The reason I ask is because I am going to want to do three substitutions,
 and I'd rather not do three str_replace calls if I don't have to. Plus the
 latter seems to be a more robust way of making the changes.
 
 Thanks, and apologies if this has been asked before and I missed it. I'm
 just not sure how to phrase this for a search engine.
 
 Nelson 
 
 
 You could use an existing templating solution, like Smarty, although for
 what you want to do it might be overkill. A few str_replace() calls
 shouldn't produce too much overhead, but it depends on the size of the
 text string in question. If it's just a couple of paragraphs of text, no
 problem, something closer to a whole chapter of a book will obviously be
 more expensive.
 
 You could try eval() on the block of text, but if you do, be really
 careful about what text you're using. I wouldn't recommend this if
 you're using any text supplied by a user. As a last option, you could
 have the text stored as separate parts which you join together in one
 string later. This might be less expensive in terms of processing power
 required, but it also makes maintenance more of a hassle later.
 
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 


RE: [PHP] variable placeholders in a text file

2012-12-31 Thread Nelson Green

On Mon, 31 Dec 2012 19:59:02, Ashley Sheridan wrote:
___
  
 On Mon, 2012-12-31 at 13:39 -0600, Nelson Green wrote: 

 
 My question is, is there another way to do something similar, such as 
 embedding a variable name directly into the text file? In other words, 
 instead of my text file reading: 
  
 Hello USER ... 
  
 Can I do something like this: 
  
 Hello $user_name ... 
  
 and then write my function to replace $user_name with the passed 
 parameter prior to printing? 
  

  
 You could use an existing templating solution, like Smarty, although  
 for what you want to do it might be overkill. A few str_replace() calls  
 shouldn't produce too much overhead, but it depends on the size of the  
 text string in question.
  
 You could try eval() on the block of text, but if you do, be really  
 careful about what text you're using. I wouldn't recommend this if  
 you're using any text supplied by a user. As a last option, you could  
 have the text stored as separate parts which you join together in one  
 string later. This might be less expensive in terms of processing power  
 required, but it also makes maintenance more of a hassle later. 
  
  
 Thanks, 
 Ash 
 http://www.ashleysheridan.co.uk 

Hi Ash,

Yep, smarty would be way more than I need right now. I'm just dabbling with
various things, trying to learn more about PHP. And my first thought was to
split the components, which worked fine. Then I tried a HEREDOC which did
allow variable substitution. This attempt is a move up from that, trying to
generalize things a bit more. My input will be 100% generated by me, but in the
back of my mind I'm looking towards the ability to use user supplied strings.
  
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] variable placeholders in a text file

2012-12-31 Thread Nelson Green

On Mon, 31 Dec 2012 14:47:20 Stephen D wrote:

 Yes!

 Easy standard stuff.

 $title = 'Mr.;
 $user_name = 'John Doe';

 $message = Hello $title $user_name 

 Just define the value for the variables before defining the value for
 the message.

 Note that $message has to use double quotes for the expansion. Also
 consider using HEREDOC instead of the double quotes.

 You may want to put your message in a text file and using the include
 function.

Hi Stephen,

My message is in a text file, but I'm using fopen and fread in a self-defined
function, so message is actually defined as (GREETER_FILE is a defined
constant):
function print_greeting($user_name)
{ 
   $handle   = fopen(GREETER_FILE, r);
   $message  = fread($file_handle, filesize(GREETER_FILE));
   $msg_text = str_replace(USER, $user_name, $message);
   
   print($msg_txt);
}

And my text file is simply:
$cat greet.txt
Hello USER. How are you today?

If I change USER to $user_name in the text file and change the print function
parameter to $message, $user_name gets printed verbatim. In other words
the greeting on my page becomes:
Hello $user_name. How are you today?

I want to pass the name Nelson to the function, and have it output:
Hello Nelson. How are you today?

after the function reads in text file input that contains a variable placeholder
for the user name. I actually had a HEREDOC in the function, and that worked.
But by reading a file instead, I can make things more flexible. I'd rather be
changing a text file instead of a code file.
  
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variable placeholders in a text file

2012-12-31 Thread tamouse mailing lists
On Mon, Dec 31, 2012 at 2:37 PM, Nelson Green nelsongree...@hotmail.com wrote:

 On Mon, 31 Dec 2012 14:47:20 Stephen D wrote:

 Yes!

 Easy standard stuff.

 $title = 'Mr.;
 $user_name = 'John Doe';

 $message = Hello $title $user_name 

 Just define the value for the variables before defining the value for
 the message.

 Note that $message has to use double quotes for the expansion. Also
 consider using HEREDOC instead of the double quotes.

 You may want to put your message in a text file and using the include
 function.

 Hi Stephen,

 My message is in a text file, but I'm using fopen and fread in a self-defined
 function, so message is actually defined as (GREETER_FILE is a defined
 constant):
 function print_greeting($user_name)
 {
$handle   = fopen(GREETER_FILE, r);
$message  = fread($file_handle, filesize(GREETER_FILE));
$msg_text = str_replace(USER, $user_name, $message);

print($msg_txt);
 }

 And my text file is simply:
 $cat greet.txt
 Hello USER. How are you today?

 If I change USER to $user_name in the text file and change the print function
 parameter to $message, $user_name gets printed verbatim. In other words
 the greeting on my page becomes:
 Hello $user_name. How are you today?

 I want to pass the name Nelson to the function, and have it output:
 Hello Nelson. How are you today?

 after the function reads in text file input that contains a variable 
 placeholder
 for the user name. I actually had a HEREDOC in the function, and that worked.
 But by reading a file instead, I can make things more flexible. I'd rather be
 changing a text file instead of a code file.

I use the include(template) method for this alla time, it works
great. Most especially for HTML emails coming from a web site to a
group of users, just slick as anything. include does basically just
what your print_greeting function does less the actual printout, but
using php variables instead of a str_replace. Also, this way the
templates can be stored elsewhere, outside the actual code base if
need be.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variable placeholders in a text file

2012-12-31 Thread Bastien


Bastien Koert

On 2012-12-31, at 4:58 PM, tamouse mailing lists tamouse.li...@gmail.com 
wrote:

 On Mon, Dec 31, 2012 at 2:37 PM, Nelson Green nelsongree...@hotmail.com 
 wrote:
 
 On Mon, 31 Dec 2012 14:47:20 Stephen D wrote:
 
 Yes!
 
 Easy standard stuff.
 
 $title = 'Mr.;
 $user_name = 'John Doe';
 
 $message = Hello $title $user_name 
 
 Just define the value for the variables before defining the value for
 the message.
 
 Note that $message has to use double quotes for the expansion. Also
 consider using HEREDOC instead of the double quotes.
 
 You may want to put your message in a text file and using the include
 function.
 
 Hi Stephen,
 
 My message is in a text file, but I'm using fopen and fread in a self-defined
 function, so message is actually defined as (GREETER_FILE is a defined
 constant):
 function print_greeting($user_name)
 {
   $handle   = fopen(GREETER_FILE, r);
   $message  = fread($file_handle, filesize(GREETER_FILE));
   $msg_text = str_replace(USER, $user_name, $message);
 
   print($msg_txt);
 }
 
 And my text file is simply:
 $cat greet.txt
 Hello USER. How are you today?
 
 If I change USER to $user_name in the text file and change the print function
 parameter to $message, $user_name gets printed verbatim. In other words
 the greeting on my page becomes:
 Hello $user_name. How are you today?
 
 I want to pass the name Nelson to the function, and have it output:
 Hello Nelson. How are you today?
 
 after the function reads in text file input that contains a variable 
 placeholder
 for the user name. I actually had a HEREDOC in the function, and that worked.
 But by reading a file instead, I can make things more flexible. I'd rather be
 changing a text file instead of a code file.
 
 I use the include(template) method for this alla time, it works
 great. Most especially for HTML emails coming from a web site to a
 group of users, just slick as anything. include does basically just
 what your print_greeting function does less the actual printout, but
 using php variables instead of a str_replace. Also, this way the
 templates can be stored elsewhere, outside the actual code base if
 need be.
 

This is exactly what I do. Dead simple fast and the templates are fully self 
contained.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] variable placeholders in a text file

2012-12-31 Thread Nelson Green

On 2012-12-31, at 4:58 PM, tamouse mailing lists tamouse.li...@gmail.com 
wrote:
 I use the include(template) method for this alla time, it works
 great. Most especially for HTML emails coming from a web site to a
 group of users, just slick as anything. include does basically just
 what your print_greeting function does less the actual printout, but
 using php variables instead of a str_replace. Also, this way the
 templates can be stored elsewhere, outside the actual code base if
 need be.

This sounds like it might be what I'm looking for. If I'm understanding
correctly, you are saying to use the include function to read in my
greeting file. I think I've got the basic gist of the concept, and will see
what I can hobble together real quick. This thought had not occurred
to me.

Thanks!
  
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-DB] Re: [PHP] Shopping Cart Discount System

2012-12-31 Thread Karl DeSaulniers


On Dec 31, 2012, at 3:36 AM, Ashley Sheridan wrote:




Karl DeSaulniers k...@designdrumm.com wrote:


Hello Everyone,
Hope all are well. Quick and hopefully painless question.
Is there any examples on how to build a discount system
into your shopping cart out there that anyone knows of?
I am using MySQL and PHP. I have built one of my own so far,
but am having trouble making sense of what goes where.

For example. If a product has miscellaneous charges,
lets say.. glitter is extra on your shirt.
How is discounts applied? I mean, as far as discounts go,
lets say its 20% a shirt and this shirt has glitter.
Is it best practice to apply the discount to just the shirt
or the shirt and glitter as a combo discount.
I know this is somewhat dependent on the owners choice
of what he/she wants to give the discount on,
but my question is of the programing of it.
Do I build conditions for the shirt to get a discount applied
then the miscellaneous charges, or combine the totals of the two,
then apply the discount to the sum?

Then lets say there is a cart discount also being applied.
Is it best practice to apply this to the total of items then
add the shipping, rush charges and tax, or to the total of the whole
cart
including shipping, rush charges then add the tax after applying the
discount?

Sorry for the run-on question, hope this makes sense enough to merit
help.

HNY,

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com

PS: Because this question could be answered by either database or
general, is the only reason for the double post.
Wont be making a habit of it.. :)


I would apply the discounts where they made sense from a customer  
POV. Would you expect a t-shirt discount to be applied to only the  
base item or the product as a whole? I'd say tge whole thing. You  
could have various areas in your code that apply discounts at  
different levels: per item, per group of items (bogof, etc), and per  
basket.



Thanks,
Ash
http://www.ashleysheridan.co.uk

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




That does make more sense now that you say.
I guess I would want or expect the discount to apply to the whole thing.
Thanks Ash.

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Shopping Cart Discount System

2012-12-31 Thread Karl DeSaulniers


On Dec 31, 2012, at 3:51 PM, tamouse mailing lists wrote:

On Mon, Dec 31, 2012 at 2:31 AM, Karl DeSaulniers k...@designdrumm.com 
 wrote:

Hello Everyone,
Hope all are well. Quick and hopefully painless question.
Is there any examples on how to build a discount system
into your shopping cart out there that anyone knows of?
I am using MySQL and PHP. I have built one of my own so far,
but am having trouble making sense of what goes where.

For example. If a product has miscellaneous charges,
lets say.. glitter is extra on your shirt.
How is discounts applied? I mean, as far as discounts go,
lets say its 20% a shirt and this shirt has glitter.
Is it best practice to apply the discount to just the shirt
or the shirt and glitter as a combo discount.
I know this is somewhat dependent on the owners choice
of what he/she wants to give the discount on,
but my question is of the programing of it.
Do I build conditions for the shirt to get a discount applied
then the miscellaneous charges, or combine the totals of the two,
then apply the discount to the sum?

Then lets say there is a cart discount also being applied.
Is it best practice to apply this to the total of items then
add the shipping, rush charges and tax, or to the total of the  
whole cart

including shipping, rush charges then add the tax after applying the
discount?


These sound much more like business operating questions than
programming questions, per se. I think it really depends a lot on what
other businesses in the same niche as yours do, or if you can find
out. Once you have figured out the business practices, coding them
should be easier, I'd say, but doing it the other way 'round seems
like would lead to confusion.

Some questions from a really non-business person:

1. Why are you offering discounts at all? What do you hope to
accomplish by offering discounts?
2. Who qualifies for which discounts and why?
3. Do discounts apply to just the base merchandise, or the whole end
piece, with whatever customisations it might have, and if so or if
not, why?
4. Are there different discount rates applied to base merchandise and
subsequent customisations, and if so, why?
5. Is there any reason to make this complicated, or instead just offer
a flat rate discount on final price, before taxes and SH?



My appologies if this is an OT thread. I was in the midst of coding  
these things when I asked it.
Yes, it is a little confusing. This is a small t-shirt company a  
friend and I are putting together.
I have thought out most of the business logic for the company and the  
website.
The only thing I guess I forgot to plan in was these discounts and how  
to apply them.
I currently have discounts per item and per the cart. The discounts  
are set up to apply on birthdays
and added by admins for discounting items to clear inventory. The cart  
discounts are set to apply
at a certain interval of purchase amounts. For eg. (and im really just  
throwing numbers) if someone buys $1,000
worth of merch, they are sent a 50% off your cart discount to their  
email.


I guess the question was more how to apply the discounts to the cart.  
Discount item + miscellaneous or just item.
Discount cart or cart + shipping + handling. I was also asking if  
anyone had or knew of a sample script I could pick apart.
That was probably the programing part of the question. But thank you  
guys for taking the time to answer.

I believe it helped. We will see.. :)

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variable placeholders in a text file

2012-12-31 Thread Stephen

On 12-12-31 03:37 PM, Nelson Green wrote:

On Mon, 31 Dec 2012 14:47:20 Stephen D wrote:

Yes!

Easy standard stuff.

$title = 'Mr.;
$user_name = 'John Doe';

$message = Hello $title $user_name 

Just define the value for the variables before defining the value for
the message.

Note that $message has to use double quotes for the expansion. Also
consider using HEREDOC instead of the double quotes.

You may want to put your message in a text file and using the include
function.

Hi Stephen,

My message is in a text file, but I'm using fopen and fread in a self-defined
function, so message is actually defined as (GREETER_FILE is a defined
constant):
function print_greeting($user_name)
{
$handle   = fopen(GREETER_FILE, r);
$message  = fread($file_handle, filesize(GREETER_FILE));
$msg_text = str_replace(USER, $user_name, $message);

print($msg_txt);

}

And my text file is simply:
$cat greet.txt
Hello USER. How are you today?

If I change USER to $user_name in the text file and change the print function
parameter to $message, $user_name gets printed verbatim. In other words
the greeting on my page becomes:
Hello $user_name. How are you today?

I want to pass the name Nelson to the function, and have it output:
Hello Nelson. How are you today?

after the function reads in text file input that contains a variable placeholder
for the user name. I actually had a HEREDOC in the function, and that worked.
But by reading a file instead, I can make things more flexible. I'd rather be
changing a text file instead of a code file.

The reason you get $user_name printed is because of the way you are 
populating the variable $message. You need to have $user_name embedded 
in double quotes or a HEREDOC when PHP parses $messsage. And $user_name 
has to have already been defined.


Here is a sample from one of my sites. It is a simple one for the 
contact page.


=contact.php

?php
$thispage = Contact;
$contenttop = p$thispage/p;
$contentbody = HEREDOC
pstep...@roissy.ca/p
HEREDOC;

require_once include.php;
require_once utilities.php;

echo $header . $markup;

=

The common stuff for every page is defined in the file include.php. I 
define the variable $markup in that file.


Here is the definition for $markup

$markup=HEREDOC

body
  div id=all

div id=top
  img src=$titlepng alt=$title /
/div

div id=main

  div id=mainrow

div id=left
  $leftimage

  div id=mainnav

ul
  $menu
/ul

  /div

/div

div id=content
  div id=content-top
$contenttop
  /div
  div id=content-body
$contentbody
  /div
  div id=content-bottom
  /div
/div

  /div
/div

div id=footer
  $copyright
/div

  /div

/body
/html
HEREDOC;

There is lots more code, but this is the important stuff.

By using require_once instead of fopen and fread, I have simpler code 
and PHP evaluates the embedded variables in $markup without any need to 
use string functions.


In your case, I would make the file greeter.php

=greeter.php===
$message = Hello $user_name. How are you today?
===

You replace the fopen and fread stuff with a require_once function and 
$message gets included and the user name resolved all in one line of code.


Hope this helps

--
Stephen


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] SOLVED: variable placeholders in a text file

2012-12-31 Thread Nelson Green

On Mon, 31 Dec 2012 1On Mon, 31 Dec 2012 17:47:00 Stephen D wrote:

 By using require_once instead of fopen and fread, I have simpler code
 and PHP evaluates the embedded variables in $markup without any need to
 use string functions.

 In your case, I would make the file greeter.php

 =greeter.php===
 $message = Hello $user_name. How are you today?
 ===

 You replace the fopen and fread stuff with a require_once function and
 $message gets included and the user name resolved all in one line of code.

 Hope this helps

 --
 Stephen

Aha! Thanks for the more detailed explanation. I totally misunderstood your
first reply. I understood why I was seeing $user_name instead of Nelson,
but I did not understand what you were trying to tell me.

My greeter file is now:
?php
$message=HEREDOC
Hello $user_name.
How are you today?
HEREDOC;
?

And my function is simply:
function print_greeting($user_name)
{
   require_once GREETER_FILE;
   print($message);
}

Now when I call the function, passing the string Nelson, it is printing
exactly as I wanted. I used a HEREDOC in the GREETER_FILE because I want to
make it more than that one message, and I want to preserve the line breaks
and formatting when I do.

From what I've been reading based on other replies, I think templating
will be the way for me to go at some point. I am trying to design a fairly
simple site that will be used internally as a front-end to a simple inventory
database that I've designed. The back-end works fine, but command line result
sets don't appeal to others, so I've embarked on a front-end design. Your
help has gotten me over this step and I can start to expand things. I find
I learn best when I start with some basic functionality and build it up. My
first incarnation was to simply build a static page that output exactly what
I put into it. Once I got that going, I then broke parts off into functions,
and then added parameter passing to the functions. I've already explained
where it went from there to here.

Not to detract from the other replies, but you have lead me to exactly what
I was looking for at the moment. I find smarty (and now a couple of others
picked up from reading about smarty) to be fascinating stuff, but I'm nowhere
near that point yet.

Thanks a million!
Nelson
  
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variable placeholders in a text file

2012-12-31 Thread tamouse mailing lists
On Mon, Dec 31, 2012 at 5:47 PM, Stephen stephe...@rogers.com wrote:
 The common stuff for every page is defined in the file include.php. I
 define the variable $markup in that file.

 Here is the definition for $markup

 $markup=HEREDOC
[[snippy]]
 HEREDOC;

 By using require_once instead of fopen and fread, I have simpler code and
 PHP evaluates the embedded variables in $markup without any need to use
 string functions.

While using the *_once works in many cases, if you're doing a mass
mailing kind of thing, you want to use the standard include/require so
you can re-include it as your variables change:

foreach ($customers as $customer) {
  $fullname = $customer['fullname'];
  $address = $customer['address'];
  // and so on
  include(mailing.php);
  process($mailing,$customer);
}

where mailing.php defines the $mailing variable as the content that
got included and substituted.

(Back before I came up with this, I was starting off in the same place
as the OP -- and then I just realized wait --- PHP *IS* a templating
system! a voila)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php