Jump to content

jcc5018

New Members
  • Posts

    2
  • Joined

  • Last visited

jcc5018's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the feed back. I am sorry it is long, but I'm not sure how to explain things without showing the whole set of code. keep in mind, the functions above, unless otherwise stated were designed first without classes. I havent converted everything yet, because I was confusing myself. I'm not sure I understand your example for the client levels. I have no idea what those numbers are that you included. My guess is you may be misunderstanding the purpose of the level. So Let me explain. The purpose of the client level is to allow for multiple price list for my customers. Say I want to give one customer a discounted rate, then their level may be medium or low. No numbers are associated with the client level. The default rate is high. This could also be used to set site wide discounts, as my levels are not simply calculated based on percentages off. Each product has three different multipliers. For example, A photo print will have a multiplier for the high, med, and low as 0.5, 0.4, 0.3 . Then it will also have one of 6 m_types, in this case "area" as all prints are calculated based on the area of the print. other types would calculate based on cost of good sold, flat rate, commission, or the number of images selected for the product (photo albums) So the page will load the proper multiplier value based on what the client level is. Next, the page loops through all the product variants that are children of the product and sets them in a list. Each variant has the missing information needed to calculate the final price. (area, cogs, ect.) So my 8x10 photo variant would use the calculation for area which is area *multiplier and display the proper price. The results of the high, med, low price would be $40, $32, and $24 respectively. If the client level is anything but high, then a was/ now price is displayed. There are two other values assigned to each product. That is img_min and img_max These are used to define the min and max number of images allowed to be selected for the particular product. Hopefully that clears some things up.
  2. I have been trying to figure out a somewhat complex set of functions to handle some product price calculations and display. I was thinking that building classes may be the best solution, but I don't completely know what I am doing with that either. I was hoping someone may be able to help me figure out the best solution for all this. This site is being built within wordpress. The pages load as follows, 1. Site determines client level: If no user is logged in, it defaults to client_lvl = high, if user is logged in, client_lvl may be set to an alternate value. (high, med, low) This should be loaded just once per site visit. I created this function: function get_client_lvl () {$user_id = get_current_user_id(); global $client_lvl; If ($user_id == 0) {$client_lvl= 'high';} Else {$client_lvl=get_user_meta($user_id, wpcf-client-lvl, true); } }//End function I tried converting it to a class, but I'm not sure I am doing it correctly. class ClientLvl { public $client_lvl ='high'; private $user_id; private function __construct() { $this->user_id= get_current_user_id(); } public function get_client_lvl () //check the client level from user meta- { $this->client_lvl If ($user_id != 0) {return get_user_meta($user_id, wpcf-client-lvl, true); } The rest of the functions are based on the following arrangement. Collections have multiple products which have multiple variations. The Products have a series of multiplier values attached to them. One for each client level. It also has a multiplier type (m_type) The variants then have the item specific details such as cost of goods sold (cogs), Area, sku, and name. 2. This function is used to determine which multiplier value will be used in the calculation. Used on collection and product pages to determine which multiplier value to use for calculation based on client level f unction get_multiplier($client_lvl) { $p_high= get_post_meta(get_the_ID(),'p_high','single'); $p_med= get_post_meta(get_the_ID(),'p_med','single'); $p_low =get_post_meta(get_the_ID(),'p_low','single'); if ($client_lvl == 'med') {$prices=array('high'=>$p_high,'med'=> $p_med);} elseif ($client_lvl == 'low') {$prices=array('high'=>$p_high,'low'=> $p_low);} else {$prices=array('high'=>$p_high);} }//End function I am assuminng that if I made this a class, I should just define the p_high (med, low) values and then display them with another object creation in another function? 3.These values will be used in another function to limit the number of images that a user can select for their product. $img_min= get_post_meta(get_the_ID(),'img_min','single'); $img_max= get_post_meta(get_the_ID(),'img_max','single'); 4. These are the formulas that are used to calculate the displayed price. I am not sure how to handle the image and image+commission options as they use the number of selected images to determine the price. But if no images are selected, I want it to display "This is the price/ image. One idea I thought of was to include the echo statements inside the switch options, but Im not sure how to handle the array. If the client level is High the function will only loop through once and will not have a was now price. but if it is anything else, then it will loop through twice and will have the was now echo statement. If I didnt have the special case in the image based calculations, then the was now function would work just fine. But I'm not sure where to put the conditional echo's for those functions. function calculate_price($m_type) { global $cogs; $cogs= get_post_meta(get_the_ID(),'cogs','single'); $img_cost=10; $prices= get_multiplier(); Foreach($prices as $multiplier) { switch ($m_type) { case 'Area': $area= get_post_meta(get_the_ID(),'area','single'); $total[]= $multiplier * $area; break; case 'Image': if(isset($img_count)) {$total[]= $multiplier * $cogs * $img_count;} else {$total[]= $multiplier * $cogs ;} // Displayed as $price/ Image using $img_count break; case 'Commission': $total[]= $multiplier + $cogs; break; case 'Flat': $total[]= $multiplier; break; case 'Commission+Image': if(isset($img_count)) {$total[]= $multiplier + ($img_cost*$img_count);} else {$total[]= $multiplier; } //Display "Price: ".$multiplier. "+".$img_cost ." /image" break; case 'Price': $total[]= $multiplier * $cogs; break; }}} 5. Function that displays the price result from the previous function. Does not currently account for the image or image+commission statements. I need to create a similar function that finds the lowest calculated price of a particular product group to display on the archive page for products. function was_now($client_lvl,$m_type) { $total=calculate_price($m_type); $p1=number_format($total[0],2,'.',','); If ($client_lvl == "high") { echo "is \${$p1}"; } else { $p2=number_format($total[1],2,'.',','); echo "WAS: \${$p1}<br/>"; echo "NOW: \${$p2}"; }} 6.This is the subloop of the product page that displays the variants for that product. Not fully coded yet. (This code is currently displayed in the template file itself opposed to a function. function uc_list_product($ID,$m_type) { get_page_children($ID); echo "<table> "; while ( have_posts() ) { the_post(); ?> <tr><?php if($m_type=='Image'){ $display= 'Price '. was_now($client_lvl,$m_type); //if images are selected display price*img count } elseif($m_type=='Commission+Image'){ $display= 'Price '. was_now($client_lvl,$m_type);} //display multiplier, img cost, img count else {$display= 'Price '. was_now($client_lvl,$m_type);} echo "<td>". the_title()."</td><td>Price ".$display ."</td><td><a href='#'>Select Product</a></td></tr>" ; } echo "</table>"; wp_reset_query(); } This will probably be doable with classes, but I I'm not entirely sure how to go about that. I hope someone can help me figure this out.
×
×
  • 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.