New Zenner
- Join Date:
- Aug 2012
- Posts:
- 20
- Plugin Contributions:
- 0
Product Price breakdown issues
Did you need any other info from me?
New Zenner
Did you need any other info from me?
Sensei
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.
New Zenner
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.
New Zenner
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"?
New Zenner
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.
Sensei
So the logic needs to be:
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.
New Zenner
How about following that concept with these changes:
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?
Sensei
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.
New Zenner
I got ya. Well to go with that basic setup, Here is a link to an item I already setup but obviously don't have stock working properly. It has the attribute configured with the 4 options. http://www.twistedtattoosupply.com/store/index.php?main_page=product_info&cPath=9_16&products_id=1
Sensei
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.
New Zenner
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?
Sensei
Not necessary with PHP. Here's an article on it: http://www.zen-cart.com/content.php?271-some-of-my-php-files-are-missing-the-at-the-end-of-the-file
.
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.
New Zenner
Learn something new every day :)
Tell staff why this post should be reviewed.