Forums / Setting Up Categories, Products, Attributes / Product Price breakdown issues

Product Price breakdown issues

Started by maverick3n1 on 28 Aug 2012, 3:02 AM · Views: 2,611

Results 21 to 33 of 33
12 Sep 2012, 2:11 PM
#21
maverick3n1 avatar

maverick3n1

New Zenner

Join Date:
Aug 2012
Posts:
20
Plugin Contributions:
0

Product Price breakdown issues

Did you need any other info from me?

12 Sep 2012, 8:07 PM
#22
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Product Price breakdown issues

This is a complex scenario.

In the meantime, I'm reminded that in the Attributes Controller, the Attributes have a place for Quantity Discounts on the:
(example)
Attributes Qty Price Discount:
1:11,3:10.00,6:9.00,9:8.00,12:7.00,15:6.00

Have you looked at how that might be usable?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

15 Sep 2012, 11:23 PM
#23
maverick3n1 avatar

maverick3n1

New Zenner

Join Date:
Aug 2012
Posts:
20
Plugin Contributions:
0

Re: Product Price breakdown issues

I have. I can't limit them to buying a qty of 5, 10, 25, and 50. They could buy 51, 49, 3, 7. Keeping them to those set numbers keeps inventory a lot more simplistic. My product comes in boxes of 50 and packages of 5. This breakdown is also a standard in the industry. Every supplier that supplies these products, supply them in the same qty portions. Going outside of the box could be confusing to people, and with the many not so bright individuals out there, they would have a hard time comparing prices to other competition, and may decide not to use my site because it's different then they are used to. It's stupid, but that's a consumer for ya ;)

The product I'm working with is Tattoo Needles. There are about 80 different size needles. So in all cases, the attribute would be for needles, qty 5, 10, 25, 50. The only difference would be the price of said needles. I can already create those breakdowns as the program stands. It just won't withdraw the proper inventory numbers.

16 Sep 2012, 4:12 PM
#24
maverick3n1 avatar

maverick3n1

New Zenner

Join Date:
Aug 2012
Posts:
20
Plugin Contributions:
0

Re: Product Price breakdown issues

Is there no way to add a line of code that says "If these attributes exist, withdraw 5 if attribute A is selected, 10 if Attribute B, 25 if Attribute C, 50 if Attribute D, Else, withdraw normal quantity"?

16 Sep 2012, 5:02 PM
#25
maverick3n1 avatar

maverick3n1

New Zenner

Join Date:
Aug 2012
Posts:
20
Plugin Contributions:
0

Re: Product Price breakdown issues

Actually, that's a bit too dumbed down. It would have to multiply the attribute selected by the qty put in the qty box, if the attribute existed. If the attribute didn't exist, then it would just use the quantity.

16 Sep 2012, 6:05 PM
#26
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Product Price breakdown issues

So the logic needs to be:

  • for each product
    --- look at its attributes
    ---- check whether a specific option NAME has been selected (what is the ID NUMBER for that? ie: your qty option-name)
    ------ if that NAME is selected, check its VALUE, and compare that with a list (supplied by you, and stuffed into the code) to know how many are associated with that
    -------- use that qty from the lookup and multiply it by the number of that product in the cart, and then use that number to reduce inventory.
    -- continue with rest of attributes on that product
  • continue with rest of products

Right?

a) What are the IDs for the option NAMEs involved?
b) What are the IDs for the option VALUES associated with each of those NAMEs?
c) What are the quantities associated with each ID for each option VALUE?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Sep 2012, 3:00 AM
#27
maverick3n1 avatar

maverick3n1

New Zenner

Join Date:
Aug 2012
Posts:
20
Plugin Contributions:
0

Re: Product Price breakdown issues

How about following that concept with these changes:

  • for each product
    --- look at its attributes
    ---- check whether a specific option ATTRIBUTE_QTY has been selected (an additional column in the attribute table that's either a 1 or a 0)
    ------ if that ATTRIBUTE_QTY is selected (1), check ATTRIBUTE_QTY_DEFINED (a text box within the Attribute properties where you can enter a QTY number, yet again, a second additional column to the attribute qty table)
    -------- use the qty from the lookup of ATTRIBUTE_QTY_DEFINED and multiply it by the number of that product in the cart, and then use that number to reduce inventory.
    -- continue with rest of attributes on that product
  • continue with rest of products

That would make the QTY attribute open ended rather than specific, require less customized coding that's static and can't be changed easily, and allow you to assign any qty you wanted to each attribute. It would require adding 2 additional columns to the attribute table. One of ATTRIBUTE_QTY, and if ATTRIBUTE_QTY is a 1/yes, then utilize the ATTRIBUTE_QTY_DEFINED column to define how much to multiply the normal qty by for stock count withdrawal. Does that make sense? I may be wrong, but the code changes sound simple enough, and it would allow for any variation to qty necessary for any future decision to sell items in QTY, regardless of what your QTY numbers are, with very minor changes to the code. This would allow for anyone who orders bulk packs of items to list those items in singles as well, if say they purchase a product in cases of 10 and sell them as single qty, they could list the qty as .1, so they could track their stock by cases rather than individuals. If someone buys 2 bottles of an item that comes in a case of 10 for stocking purpose, they've ordered 2 of qty .1 to equal a total of .2 cases ordered. It opens a lot of options, and it sounds like the code changes are fairly minor. Once again, I haven't coded in PHP in ages and aeons, and work with other languages that are more Visual C based, but the concepts are still fairly similar. Thoughts?

18 Sep 2012, 3:43 AM
#28
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Product Price breakdown issues

I was trying to come up with a solution that doesn't require making odd database changes that could cause incompatibility or upgrade issues. And which wouldn't require writing admin screens or customizations, especially since the qty thresholds wont' be changing much anyway.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

19 Sep 2012, 7:09 AM
#30
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Product Price breakdown issues

Try the following. It seems to work here for me.

Three things: Two new files, and one edit to an existing file.

NEW: /includes/classes/observers/class.observer_stock_decrement_by_option_value.php

<?php
/**
 * @package plugins
 * @copyright Copyright 2003-2012 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 *
 * Designed for v1.5.1, compatible with 1.3.9 and v1.5.0 also.
 */

class stock_decrement_by_option_value extends base {

  function __construct() {
    $this->attach($this, array('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN'));

    /**
     * INSTRUCTIONS:
     * The following array needs a list of option values and quantities
     * $this->optionNamesValuesToQuantities[option-name-id][option-value-id] = qty;
     */
    $this->optionNamesValuesToQuantities = array();
    $this->optionValuesToQuantities[1][1] = 5;
    $this->optionValuesToQuantities[1][2] = 10;
    $this->optionValuesToQuantities[1][3] = 25;
    $this->optionValuesToQuantities[1][4] = 50;
  }

  /**
   * Since this observer is attached to the NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN,
   * the following is fired on every product that is added to the order, just before the stock-reduction is run.
   */
  function update(&$class, $eventID, $paramsArray = array())
  {
    global $db; // this is needed later
    $i = $paramsArray['i']; // this is needed in order for the following code to know which product is being processed at the moment.
    $prodQtyInStock = $class->stock_query->fields['products_quantity'];

    // check if the product has any attributes
    if (!isset($class->products[$i]['attributes']) || !is_array($class->products[$i]['attributes']) || sizeof($class->products[$i]['attributes']) <1) return false;

    // if it has attributes, do the required lookup by checking each attribute in the basket
    foreach($class->products[$i]['attributes'] as $attribs) {
      // see whether the attribute contains an option name id related to the lookups defined in the constructor. if not, try the next one
      if (!isset($this->optionValuesToQuantities[$attribs['option_id']])) continue;

      if (isset($this->optionValuesToQuantities[$attribs['option_id']][$attribs['value_id']])) {
        // get the qty from the array values set in the constructor
        $qtyToReduceBy = $this->optionValuesToQuantities[$attribs['option_id']][$attribs['value_id']];
        // multiply it by the number of this item actually added to the cart
        $qtyToReduceBy = ($qtyToReduceBy * $class->products[$i]['qty']);
        // subtract from qty on-hand in db
        $newStockQty = $prodQtyInStock - $qtyToReduceBy;
        // pass back the new qty by overriding the lookup query being used by the normal stock handler
        $class->stock_query = $db->Execute("SELECT " . $newStockQty . " as products_quantity, 'attribQtyHandler' as products_attributes_filename from " . TABLE_PRODUCTS . " where products_id = " . zen_get_prid($class->products[$i]['id']));
        $class->products[$i]['stock_reduce'] = $qtyToReduceBy;
      }
    }
  }
}

NEW: /includes/auto_loaders/config.observer_stock_decrement_by_option_value.php

<?php
/**
 *
 * @package plugins
 * @copyright Copyright 2003-2012 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 */
/**
 * Designed for v1.5.1, compatible with 1.3.9 and v1.5.0 also.
 */
if (!defined('IS_ADMIN_FLAG')) {
 die('Illegal Access');
}
$autoLoadConfig[190][] = array('autoType'=>'class',
                              'loadFile'=>'observers/class.observer_stock_decrement_by_option_value.php');
$autoLoadConfig[190][] = array('autoType'=>'classInstantiate',
                              'className'=>'stock_decrement_by_option_value',
                              'objectName'=>'stock_decrement_by_option_value');

EDIT /includes/classes/order.php:
Line 720 (in v1.5.0) (or line 716 in v1.5.1), change from this:$this->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN'); to be 3 lines like this: ```
$this->stock_query = $stock_values;
$this->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN', array('i'=>$i));
$stock_values = $this->stock_query;

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

20 Sep 2012, 3:01 AM
#31
maverick3n1 avatar

maverick3n1

New Zenner

Join Date:
Aug 2012
Posts:
20
Plugin Contributions:
0

Re: Product Price breakdown issues

Shouldn't I close the php tag on each of the new files with ?> or is that no longer required in the latest version of php?

20 Sep 2012, 3:26 AM
#32
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Product Price breakdown issues

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

20 Sep 2012, 2:02 PM
#33
maverick3n1 avatar

maverick3n1

New Zenner

Join Date:
Aug 2012
Posts:
20
Plugin Contributions:
0

Re: Product Price breakdown issues

Learn something new every day :)