Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Posts
    2
    Plugin Contributions
    0

    Default Problem with text attribute and update_quantity()

    Zen Cart 1.3.8a

    I'm trying to update the qty of products in the shopping cart that contain attributes including a text attribute. After the update occurs, all attributes remain but the text attribute disappears. How do I pass the correct $attributes parameter in the update_quantity function to make this work.

    My simplified observer class class.test.php

    <?php
    class test extends base {

    function test() {
    $_SESSION['cart']->attach($this,array('NOTIFIER_CART_ADD_CART_END', NOTIFIER_CART_REMOVE_END'));
    }

    function update(&$class, $eventID) {
    $products = $_SESSION['cart']->get_products();
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
    $_SESSION['cart']->update_quantity($products[$i] ['id'],5,$products[$i]['attributes']);
    }
    }
    }
    ?>

  2. #2
    Join Date
    Jun 2009
    Posts
    2
    Plugin Contributions
    0

    Default Re: Problem with text attribute and update_quantity()

    I finally figured this out (I'm a newby at php programming and wasn't familiar with associative arrays).

    $products[$i]['attributes'] does not include the attribute values for text attributes. You have to get text values out of the $products[$i]['attributes_values'] array. I solved this by generating a new attributes array to pass to update_quantity() which contains the text attribute values. You have to look at each array element to see if it's a text value then update the $key and $value in the new array. Here's the simplified code:

    function update(&$class, $eventID) {
    $total = $_SESSION['cart']->count_contents();
    $products = $_SESSION['cart']->get_products();

    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
    foreach ($products[$i]['attributes'] as $key => $value){
    if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
    $text = $products[$i]['attributes_values'][$key];
    $new_key = TEXT_PREFIX . $key;
    $products[$i]['new_attributes'][$new_key]=$text;
    } else {
    $products[$i]['new_attributes'][$key]=$value;
    }
    }

    }

    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
    $_SESSION['cart']->update_quantity($products[$i]['id'],5,$products[$i]['new_attributes']);
    }
    }

 

 

Similar Threads

  1. v151 Problem with text product attribute
    By RobertKlumpp in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 10 Feb 2013, 10:49 PM
  2. v138a Picture upload attribute with and image and the word TEXT
    By RichardH in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 16 Apr 2012, 08:13 PM
  3. Problem with Text Attribute
    By tsrplatelayer in forum Setting Up Categories, Products, Attributes
    Replies: 11
    Last Post: 14 May 2011, 01:42 PM
  4. how to include text and image with text attribute?
    By damos in forum Customization from the Admin
    Replies: 1
    Last Post: 10 Nov 2008, 11:10 AM
  5. Problem with attribute images with text attributes...
    By aaelghat in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 17 Mar 2008, 04:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg