Zen Cart Logo
Forums / All Other Contributions/Addons / Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Views: 658,363

Results 1,141 to 1,160 of 3,609
08 Apr 2011, 16:15
#1141
derek_bryant avatar

derek_bryant

Zen Follower

Join Date:
Jul 2008
Location:
Bristol UK
Posts:
162
Plugin Contributions:
0

Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Thanks Athena

Do I have to uninstall the mod or can I just overwrite the files?
Do I have to run the SQL script again?

Where do I find:
/includes/modules/pages/shopping_cart/header_php.php in the AJAX version, with the one from stock by attributes MULTIADD

all the best

Derek

08 Apr 2011, 16:18
#1142
derek_bryant avatar

derek_bryant

Zen Follower

Join Date:
Jul 2008
Location:
Bristol UK
Posts:
162
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

I notice :

Product 189/226

Stock by Attributes

Download Now!
File size: 123897 bytes
Downloaded: 25202 times Zen Cart™ Version: v1.3.9
Version: 1.1.13
Last Updated: Apr 06 2011
Author: That Software Guy
PHP 5.3 Compatible?: Yes

This add-on allows a store owner to set a stock value for each variant of a product. For example, if you have three sizes, large, medium and small, this module will allow you to keep track of all the different quantities. It will work for a virtually unlimited number of amount of attribute combinations. For example, if you offered cotton or polyester shirts in green, red or blue and small medium or large sizes, this add-on would allow you to enter and maintain a separate stock level for each of the 18 possible combinations.

This version is unlikely to work in versions of Zen Cart prior to 1.3.5. If you are running Zen Cart 1.2.5-1.2.7d, please use the "products_with_attributes_stock" add-on by dafonz. If you are using versions 1.3.0 - 1.3.0.2 please use "Stock Attributes by danielcor".


Fix for includes/modules/pages/shopping_cart/header_php.php
Author: That Software Guy
Version: 1.1.13
Zen Cart™ Version: v1.3.9
Update added on Apr 06 2011

is this the one to use?

08 Apr 2011, 17:21
#1143
athena avatar

athena

Totally Zenned

Join Date:
Jan 2006
Location:
NM
Posts:
740
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

I'm not a moderator here but this is what worked for me:

Yes, You can over write the files.

for the version you installed i don't think you need to run any additional sql statments

here is the one from the "stock_by_attributes_4-7MULTIADD"

just replace the code in shopping_cart/header_php.php with this:

<?php
/**
 * shopping_cart header_php.php
 *
 * @package page
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: header_php.php 0000 2007-12-02 00:00:00Z kuroi $
 */

// This should be first line of the script:
$zco_notifier->notify('NOTIFY_HEADER_START_SHOPPING_CART');

require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
$breadcrumb->add(NAVBAR_TITLE);

// Validate Cart for checkout
$_SESSION['valid_to_checkout'] = true;
$_SESSION['cart_errors'] = '';
$_SESSION['cart']->get_products(true);

if (!$_SESSION['valid_to_checkout']) {
  $messageStack->add('shopping_cart', ERROR_CART_UPDATE . $_SESSION['cart_errors'] , 'caution');
}

// build shipping with Tare included
$shipping_weight = $_SESSION['cart']->show_weight();
/*
  $shipping_weight = 0;
  require(DIR_WS_CLASSES . 'order.php');
  $order = new order;
  require_once('includes/classes/http_client.php'); // shipping in basket
  $total_weight = $_SESSION['cart']->show_weight();
  $total_count = $_SESSION['cart']->count_contents();
  require(DIR_WS_CLASSES . 'shipping.php');
  $shipping_modules = new shipping;
  $quotes = $shipping_modules->quote();
*/
$totalsDisplay = '';
switch (true) {
  case (SHOW_TOTALS_IN_CART == '1'):
  $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . TEXT_TOTAL_WEIGHT . $shipping_weight . TEXT_PRODUCT_WEIGHT_UNIT . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  break;
  case (SHOW_TOTALS_IN_CART == '2'):
  $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . ($shipping_weight > 0 ? TEXT_TOTAL_WEIGHT . $shipping_weight . TEXT_PRODUCT_WEIGHT_UNIT : '') . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  break;
  case (SHOW_TOTALS_IN_CART == '3'):
  $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  break;
}

// testing/debugging
//  require(DIR_WS_MODULES . 'debug_blocks/shopping_cart_contents.php');

$flagHasCartContents = ($_SESSION['cart']->count_contents() > 0);
$cartShowTotal = $currencies->format($_SESSION['cart']->show_total());

$flagAnyOutOfStock = false;
$products = $_SESSION['cart']->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
  if (($i/2) == floor($i/2)) {
    $rowClass="rowEven";
  } else {
    $rowClass="rowOdd";
  }
  switch (true) {
    case (SHOW_SHOPPING_CART_DELETE == 1):
    $buttonDelete = true;
    $checkBoxDelete = false;
    break;
    case (SHOW_SHOPPING_CART_DELETE == 2):
    $buttonDelete = false;
    $checkBoxDelete = true;
    break;
    default:
    $buttonDelete = true;
    $checkBoxDelete = true;
    break;
    $cur_row++;
  } // end switch
  $attributeHiddenField = "";
  $attrArray = false;
  $productsName = $products[$i]['name'];

  if (STOCK_CHECK == 'true') {
    $flagStockCheck = zen_check_stock($products[$i]['id'], $products[$i]['quantity']);
    if ($flagStockCheck == true) {
      $flagAnyOutOfStock = true;
    }
	  $stockAvailable = zen_get_products_stock($products[$i]['id']);
  }

  // Push all attributes information in an array
  if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
    if (PRODUCTS_OPTIONS_SORT_ORDER=='0') {
      $options_order_by= ' ORDER BY LPAD(popt.products_options_sort_order,11,"0")';
    } else {
      $options_order_by= ' ORDER BY popt.products_options_name';
    }
    foreach ($products[$i]['attributes'] as $option => $value) {
      $attributes = "SELECT popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
                     FROM " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                     WHERE pa.products_id = :productsID
                     AND pa.options_id = :optionsID
                     AND pa.options_id = popt.products_options_id
                     AND pa.options_values_id = :optionsValuesID
                     AND pa.options_values_id = poval.products_options_values_id
                     AND popt.language_id = :languageID
                     AND poval.language_id = :languageID " . $options_order_by;

      $attributes = $db->bindVars($attributes, ':productsID', $products[$i]['id'], 'integer');
      $attributes = $db->bindVars($attributes, ':optionsID', $option, 'integer');
      $attributes = $db->bindVars($attributes, ':optionsValuesID', $value, 'integer');
      $attributes = $db->bindVars($attributes, ':languageID', $_SESSION['languages_id'], 'integer');
      $attributes_values = $db->Execute($attributes);
      //clr 030714 determine if attribute is a text attribute and assign to $attr_value temporarily
      if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
        $attributeHiddenField .= zen_draw_hidden_field('id[' . $products[$i]['id'] . '][' . TEXT_PREFIX . $option . ']',  $products[$i]['attributes_values'][$option]);
        $attr_value = $products[$i]['attributes_values'][$option];
      } else {
        $attributeHiddenField .= zen_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
        $attr_value = $attributes_values->fields['products_options_values_name'];
      }

      $attrArray[$option]['products_options_name'] = $attributes_values->fields['products_options_name'];
      $attrArray[$option]['options_values_id'] = $value;
      $attrArray[$option]['products_options_values_name'] = zen_output_string_protected($attr_value) ;
      $attrArray[$option]['options_values_price'] = $attributes_values->fields['options_values_price'];
      $attrArray[$option]['price_prefix'] = $attributes_values->fields['price_prefix'];
    }

		if ( STOCK_CHECK == 'true' ) {

			// Added to allow individual stock of different attributes
			unset($attributes);
			if(is_array($products[$i]['attributes'])){
				$attributes = $products[$i]['attributes'];
			} else {
				$attributes = '';
			}

			// End change

			$stock_check = zen_check_stock($products[$i]['id'], $products[$i]['quantity'],$attributes);
	
			if (zen_not_null($stock_check))
			{
				$flagAnyOutOfStock = true;
				$flagStockCheck = $stock_check;
			  $stockAvailable = zen_get_products_stock($products[$i]['id'], $attributes);		
			}
		}
  } //end foreach [attributes]
  $linkProductsImage = zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']);
  $linkProductsName = zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']);
  $productsImage = (IMAGE_SHOPPING_CART_STATUS == 1 ? zen_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT) : '');
  $show_products_quantity_max = zen_get_products_quantity_order_max($products[$i]['id']);
  $showFixedQuantity = (($show_products_quantity_max == 1 or zen_get_products_qty_box_status($products[$i]['id']) == 0) ? true : false);
//  $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('products_id[]', $products[$i]['id']) . zen_draw_hidden_field('cart_quantity[]', 1);
//  $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', 1);
  $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', $products[$i]['quantity']);
  $showMinUnits = zen_get_products_quantity_min_units_display($products[$i]['id']);
  $quantityField = zen_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"');
  $buttonUpdate = ((SHOW_SHOPPING_CART_UPDATE == 1 or SHOW_SHOPPING_CART_UPDATE == 3) ? zen_image_submit(ICON_IMAGE_UPDATE, ICON_UPDATE_ALT) : '') . zen_draw_hidden_field('products_id[]', $products[$i]['id']);
  $productsPrice = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');
  $productsPriceEach = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');
  $productArray[$i] = array('attributeHiddenField'=>$attributeHiddenField,
                            'flagStockCheck'=>$flagStockCheck,
                            'flagShowFixedQuantity'=>$showFixedQuantity,
                            'linkProductsImage'=>$linkProductsImage,
                            'linkProductsName'=>$linkProductsName,
                            'stockAvailable'=>$stockAvailable,
                            'productsImage'=>$productsImage,
                            'productsName'=>$productsName,
                            'showFixedQuantity'=>$showFixedQuantity,
                            'showFixedQuantityAmount'=>$showFixedQuantityAmount,
                            'showMinUnits'=>$showMinUnits,
                            'quantityField'=>$quantityField,
                            'buttonUpdate'=>$buttonUpdate,
                            'productsPrice'=>$productsPrice,
                            'productsPriceEach'=>$productsPriceEach,
                            'rowClass'=>$rowClass,
                            'buttonDelete'=>$buttonDelete,
                            'checkBoxDelete'=>$checkBoxDelete,
                            'id'=>$products[$i]['id'],
                            'attributes'=>$attrArray);
} // end FOR loop


// This should be last line of the script:
$zco_notifier->notify('NOTIFY_HEADER_END_SHOPPING_CART');
08 Apr 2011, 18:00
#1144
derek_bryant avatar

derek_bryant

Zen Follower

Join Date:
Jul 2008
Location:
Bristol UK
Posts:
162
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

many thanks Athena - that seems to have done the trick!!

Derek

09 Apr 2011, 14:45
#1146
athena avatar

athena

Totally Zenned

Join Date:
Jan 2006
Location:
NM
Posts:
740
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

ryan2416:

Hi Athena,

I couldn't tell if you were responding to my post in:
http://www.zen-cart.com/forum/showpost.php?p=1014411&postcount=1132

Can you tell if in your version that it fixes this issue?

Thanks!

Yes, I think my fix will work for you.

It is just this one file that software guy said was fixed in the newest mod for stock by attributes, but it still didn't work for me and i have a fresh install of 1.3.9h with the .13 stock by attributes mod.

I am not code savvy enough to understand why the shopping_cart/header_php.php page above from the older vesion works...i'd rather the .13 mod be fixed...but it does work to replace that one file with the code in my post above.

10 Apr 2011, 15:04
#1147
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Can anyone tell me why my sort order for stock_id in products_with_attributes_stock.php is reversed? The higher stock ID's are displayed in descending order... even though it should be in ascending order I would think.

11 Apr 2011, 15:44
#1148
ryan2416 avatar

ryan2416

New Zenner

Join Date:
Apr 2011
Posts:
4
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

athena:

Yes, I think my fix will work for you.

It is just this one file that software guy said was fixed in the newest mod for stock by attributes, but it still didn't work for me and i have a fresh install of 1.3.9h with the .13 stock by attributes mod.

I am not code savvy enough to understand why the shopping_cart/header_php.php page above from the older vesion works...i'd rather the .13 mod be fixed...but it does work to replace that one file with the code in my post above.

athena -

Thanks so much, that did the trick!

12 Apr 2011, 09:06
#1149
derek_bryant avatar

derek_bryant

Zen Follower

Join Date:
Jul 2008
Location:
Bristol UK
Posts:
162
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Some customers are getting the message 'Whoops! Sorry, but you are not allowed to perform the action requested'
and are therefore not able to complete the checkout procedure - please can anyone help

Derek

12 Apr 2011, 12:56
#1150
athena avatar

athena

Totally Zenned

Join Date:
Jan 2006
Location:
NM
Posts:
740
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

do a search of this thread for that statement and research those posts...i don't know the answer but it should be there.... search "Whoops! Sorry" in quotes

15 Apr 2011, 02:00
#1152
moggi1964 avatar

moggi1964

New Zenner

Join Date:
Mar 2009
Location:
New Jersey USA
Posts:
67
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

I am running 1.39h and the latest release of SBA.

I now cannot get ZC to accept an attribute on a new product. I choose the Option Value and Name and hit Insert and it just throws me back to the admin index page but doesn't record anything.

I tried adding a new attribute to an existing product that has a range of attributes under Size and it does the same.

Any thoughts? I have a new product launching on Saturday and want to be able to enter stock.

Thanks in advance.

15 Apr 2011, 15:07
#1153
athena avatar

athena

Totally Zenned

Join Date:
Jan 2006
Location:
NM
Posts:
740
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

I just went in and did the same and I noticed that the page was just needing time to refresh.

You asked for any thoughts...it worked, but could be just be the server is not keeping up.

I went back and repeated the process and found the new attribute only showed when I added a quantity for it.

the old attribute with 0 shows as it always has, but is not updating the quantity from products_with_attributes_stock.php even though a little box comes alive when clicked in to do so.

Updating the quantity of the newly set up attribute by clicking "add quantity for product variet" revealed the new attribute in the drop down..

15 Apr 2011, 15:26
#1154
moggi1964 avatar

moggi1964

New Zenner

Join Date:
Mar 2009
Location:
New Jersey USA
Posts:
67
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

athena:

I just went in and did the same and I noticed that the page was just needing time to refresh.

You asked for any thoughts...it worked, but could be just be the server is not keeping up.

I went back and repeated the process and found the new attribute only showed when I added a quantity for it.

the old attribute with 0 shows as it always has, but is not updating the quantity from products_with_attributes_stock.php even though a little box comes alive when clicked in to do so.

Updating the quantity of the newly set up attribute by clicking "add quantity for product variet" revealed the new attribute in the drop down..

Athena,
I can't even list an attribute in the new product that I have added so it doesn't show up in the SBA screen.

I upgraded from a release of SBA that I downloaded last May (not sure which release) and ran the update 1_4_10 sql when I did that. I transferred each file individually to the respective folder to be sure I got it correct.

So my issue lies in ZC perhaps rather than your addon? I tried changing values of stock in hand in SBA and that worked.

If I can't find a fix today I will have to revisit it next week as I have a trade show this weekend. I may just uninstall and reinstall SBA first then if the problem is not resolved then reinstall ZC 1.39h.

If I misunderstood something in your post do let me know.

Gotta go pick up the new t-shirts so back later :clap:

15 Apr 2011, 16:17
#1155
athena avatar

athena

Totally Zenned

Join Date:
Jan 2006
Location:
NM
Posts:
740
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

There is a new download for SBA and if you just installed 1.3.9h like I did grab that one.

I would leave the sql alone since you ran that already and just upload those SBA files comparing the few edits that are required for core files.

I'm not really sure why replacing the file as I've posted here in my earlier posts work, namely: /includes/modules/pages/shopping_cart/header_php.php with the one in my post above; but it was essential to getting the product quantities to play nice in the shopping cart for myself and some others.

good luck with your show!

16 Apr 2011, 00:50
#1156
moggi1964 avatar

moggi1964

New Zenner

Join Date:
Mar 2009
Location:
New Jersey USA
Posts:
67
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

athena:

There is a new download for SBA and if you just installed 1.3.9h like I did grab that one.

I would leave the sql alone since you ran that already and just upload those SBA files comparing the few edits that are required for core files.

I'm not really sure why replacing the file as I've posted here in my earlier posts work, namely: /includes/modules/pages/shopping_cart/header_php.php with the one in my post above; but it was essential to getting the product quantities to play nice in the shopping cart for myself and some others.

good luck with your show!

I'm using Apr 06 2011 v1.3.9 1.4.13 so I guess I should have ALL the correct files.

I'll go back and overwrite and see what that achieves.

Thanks for the kind wishes.

16 Apr 2011, 01:27
#1157
moggi1964 avatar

moggi1964

New Zenner

Join Date:
Mar 2009
Location:
New Jersey USA
Posts:
67
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

RESOLVED:

Forgot to reset the configure.php files in ZC to 777 after upgrade :oops:

Hopefully my idiocy will benefit someone else :yes:

Thanks for the assistance, Athena.

16 Apr 2011, 18:50
#1158
derek_bryant avatar

derek_bryant

Zen Follower

Join Date:
Jul 2008
Location:
Bristol UK
Posts:
162
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

update - I've uninstalled the stock by attributes module and the "Whoops etc." message has disappeared

20 Apr 2011, 23:21
#1159
treece avatar

treece

New Zenner

Join Date:
Aug 2008
Posts:
47
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Athena,

Thanks for the fix. I have 1.3.9h and did a first-time install of the latest SBA module and kept getting a blank page when putting something in the shopping cart. Changing the header_php.php file as you suggested solved this.

:clap:

27 Apr 2011, 17:13
#1160
treece avatar

treece

New Zenner

Join Date:
Aug 2008
Posts:
47
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

I was also getting the "Whoops" message and so were the customers.

I checked the file:

  • /includes/classes/shopping_cart.php

against the file included in 1.3.9h and found that I was using an older version. Replaced it with the new file and problem appears to be gone.
Haven't received any new orders or complaints yet, but will report back if I have any more issues.