Skip to content

Commit

Permalink
Merge pull request zencart#3629 from scottcwilson/default_attr
Browse files Browse the repository at this point in the history
Fixes default attribute issues
  • Loading branch information
drbyte committed Jun 30, 2020
2 parents 9a0f314 + 1681f34 commit e78173e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
14 changes: 12 additions & 2 deletions includes/classes/shopping_cart.php
Expand Up @@ -236,7 +236,17 @@ function reset($reset_database = false) {
function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
global $db, $messageStack;
if ($this->display_debug_messages) $messageStack->add_session('header', 'FUNCTION ' . __FUNCTION__, 'caution');

if (zen_has_product_attributes($products_id, 'false') && empty($attributes)) {
if (!zen_requires_attribute_selection($products_id)) {
// Build attributes array; determine correct qty
$attributes = array();
$query = $db->Execute("SELECT options_id, options_values_id FROM " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = " . (int)$products_id);
foreach ($query as $attr_rec) {
$attributes[$attr_rec['options_id']] = $attr_rec['options_values_id'];
}
$qty += $this->in_cart_product_total_quantity($products_id);
}
}
if (!is_numeric($qty) || $qty < 0) {
// adjust quantity when not a value
$chk_link = '<a href="' . zen_href_link(zen_get_info_page($products_id), 'cPath=' . (zen_get_generated_category_path_rev(zen_get_products_category_id($products_id))) . '&products_id=' . $products_id) . '">' . zen_get_products_name($products_id) . '</a>';
Expand Down Expand Up @@ -1977,7 +1987,7 @@ function actionBuyNow($goto, $parameters) {

$this->flag_duplicate_msgs_set = FALSE;
if (isset($_GET['products_id'])) {
if (zen_has_product_attributes($_GET['products_id'])) {
if (zen_requires_attribute_selection($_GET['products_id'])) {
zen_redirect(zen_href_link(zen_get_info_page($_GET['products_id']), 'products_id=' . $_GET['products_id']));
} else {
$add_max = zen_get_products_quantity_order_max($_GET['products_id']);
Expand Down
12 changes: 10 additions & 2 deletions zc_install/sql/demo/README.txt
@@ -1,4 +1,13 @@
The demo_cleanup.sql script deletes ALL of records in the
Notes on Demo Data:

mysql_demo.sql can be rerun after demo_cleanup.sql is used if you are
tweaking the demo data and want to reload each time (without going through a
full re-install).

Note that mysql_demo.sql should be used from the command line only,
not from Admin > Tools > MySQL Patches (the lines are too long).

demo_cleanup.sql deletes ALL of records in the
tables listed below. It is intended for developers of demo data only.
In particular, it should not be used if you have begun adding real
data on top of demo data, because it removes data indiscriminately.
Expand Down Expand Up @@ -38,4 +47,3 @@ reviews_description
salemaker_sales
specials


3 changes: 2 additions & 1 deletion zc_install/sql/demo/mysql_demo.sql
Expand Up @@ -980,7 +980,8 @@ INSERT INTO products_attributes_download (products_attributes_id, products_attri
(1093, 'test.zip', 7, 5),
(1094, 'test2.zip', 7, 5),
(1100, 'ms_word_sample.zip', 7, 5),
(1103, 'pdf_sample.zip', 7, 5);
(1103, 'pdf_sample.zip', 7, 5),
(1105, 'pdf_sample.zip', 7, 5);

#
# Dumping data for table `products_description`
Expand Down

0 comments on commit e78173e

Please sign in to comment.