Jump to content

djforema

New Members
  • Posts

    5
  • Joined

  • Last visited

djforema's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm trying to add a value to my multi dimension array. I want to add a 'quantity' value to the inner array. This is what I have now: Array ( [0] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 ) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF ) [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang ) [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green)) [1] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 ) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF ) [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang ) [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green)) ) I'm trying to make it like this: Array ( [0] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 [quantity] => 5 ) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF [quantity] => 5) [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang [quantity] => 5) [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green [quantity] => 5)) [1] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 [quantity] => 5) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF [quantity] => 5) [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang [quantity] => 5) [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green [quantity] => 5)) ) I'm trying something like this but it isn't working. <?php //This is the array I want to add to. $product_options = $registry->toObject(); //This is the value of what I want to add to the array. With the key being 'quantity'. $number = $item->orderitem_quantity; ?> <?php foreach($product_options as $key => $quan) ?> <?php $product_options[$key]['quantity'] = $number; ?> <?php endforeach; ?>
  2. Here is the getItem() function that you were talking about. public function getItem($pk=null, $refresh=false, $emptyState=true ) { if (empty( $this->_item )) { JModelLegacy::addIncludePath( JPATH_SITE.'/components/com_j2store/models' ); $query = $this->getQuery(); // TODO Make this respond to the model's state, so other table keys can be used // perhaps depend entirely on the _buildQueryWhere() clause? $keyname = $this->getTable()->getKeyName(); $value = $this->_db->Quote( $this->getId() ); $query->where( "tbl.$keyname = $value" ); $this->_db->setQuery( (string) $query ); $item = $this->_db->loadObject(); if ($item) { //retrieve the order's items $model = JModelLegacy::getInstance( 'OrderItems', 'J2StoreModel' ); $model->setState( 'filter_orderid', $item->order_id); $model->setState( 'order', 'tbl.orderitem_name' ); $model->setState( 'direction', 'ASC' ); $item->orderitems = $model->getList(); foreach ($item->orderitems as $orderitem) { $model = JModelLegacy::getInstance( 'OrderItemAttributes', 'J2StoreModel' ); $model->setState( 'filter_orderitemid', $orderitem->orderitem_id); $attributes = $model->getList(); $attributes_names = array(); $attributes_codes = array(); $attributes_csv = array(); foreach ($attributes as $attribute) { // store a csv of the attrib names $attributes_names[] = JText::_( $attribute->orderitemattribute_name ); if($attribute->orderitemattribute_code) $attributes_codes[] = JText::_( $attribute->orderitemattribute_code ); if($attribute->orderitemattribute_type == 'select' || $attribute->orderitemattribute_type == 'radio') { $attributes_csv[] = $attribute->productattributeoptionvalue_id; } } $orderitem->attributes_names = implode(', ', $attributes_names); $orderitem->attributes_codes = implode(', ', $attributes_codes); sort($attributes_csv); $orderitem->attributes_csv = implode(',', $attributes_csv); // adjust the price $orderitem->orderitem_price = $orderitem->orderitem_price + floatval($orderitem->orderitem_attributes_price); } } $this->_item = $item; } return $this->_item; } I see that the code that I had is pretty much in this. I get that this returns '$this->_item'. I'm assuming this is an array. So in place of my original code how would I call this function? I would still need a for loop to print out the list of attributes, right? So I came up with this: <?php $newarray = getItem(); ?> <?php foreach ($newarray as $list) : ?> <?php echo $list->orderitemattribute_name.' : '.$list->orderitemattribute_value; echo '<br />'; ?> <?php end foreach; ?> Which didn't end up working. Can you give me a some pointers on what I'm doing wrong?
  3. Alright here is the link to the documentation for J2Store. http://j2store.org/support/user-guide.html I don't think this is what you were wanting. Keep in mind I am still pretty new with PHP so I am trying to help you help me as best as I can. I also went through the code and found where these functions/methods were defined. getList(): /** * Retrieves the data for a paginated list * @return array Array of objects containing the data from the database */ public function getList($refresh = false) { if (empty( $this->_list ) || $refresh) { $query = $this->getQuery($refresh); $this->_list = $this->_getList( (string) $query, $this->getState('limitstart'), $this->getState('limit') ); } return $this->_list; } I couldn't find the setState() function. I did a little research and found this on a joomla site for components. function setState( $property, $value=null ) { return $this->_state->set($property, $value); } Does this give you what you need?
  4. I am trying to print out information from a list. I thought I had this figured out but realized It was just printing out the same information over and over. This is from a Joomla website and I am using the J2store extension, just to give you the information from where this is coming from. So this is suppose to print out all the attributes from a single order. Each item in the order has any number of attributes that make it up. I am using it as an assembly site. So each assembly will have different attributes that make it up. (Hope that explains it good enough.) <?php JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_j2store/models'); $model = JModelLegacy::getInstance( 'OrderItemAttributes', 'J2StoreModel' ); ?> <?php foreach (@$items as $item) : ?> <?php //these are just printed to show the 5 different items in the same order echo $item->order_id; echo '<br />'; echo $item->orderitem_id; echo '<br />'; echo $item->orderitem_name; echo '<br />'; $model->setState( 'filter_orderitemid', $item->orderitem_id); $attributes = $model->getList(); foreach($attributes as $attribute) { if(!empty($attribute->orderitemattribute_value)) { echo $attribute->orderitemattribute_name.' : '.$attribute->orderitemattribute_value; echo '<br />'; } } echo '<br />'; ?> <?php endforeach; ?> This ends up printing out this: -------------------------------------------------------- 1402100770 49 16" Box to Stud Bracket with Open Back Box + Modular Duplex BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 52 3/4" Conduit Masonry Stub BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 53 3/4" Conduit Masonry Stub BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 51 MC Cable Whip Assembly BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 50 Span Bracket with 4 SQ. Deep 1/2''-3/4'' KO's + Modular 2 Single BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 -------------------------------------------------------- The number '1402100770' is the order number. Which in that order there were 5 items purchased. The numbers for the orderitem_id are the correct numbers for the order number. The name is also the correct for the items that were in the order. The problem is when the attributes print out. It prints the same attributes for all 5 items purchased. It seems to be printing the first items attributes for all the items in the order. I can't figure out why the orderitem_id and orderitem_name all prints out correctly but when it prints of the attributes it just prints the same attributes for all the items in the order.
  5. I'm using the J2Store add-on for Joomla. The store prints out a invoice and I am editing what prints out. Right now it prints out each item ordered and the 'options' with that item. (Ex. You can order a Large shirt the options are its a t-shirt and blue.) What I'm trying to do is make a list of all the material ('options') and quanities in each order. Below is the section of code I have been working with. I added '<?php echo count($item); ?>' to the code but it just lists the 'options' then a 1 after, but only for one item in the order. The J2Store support told me this: " first you need to decode the $item->orderitem_attributes Then you need to parse through the array and get the options in a required format by sorting and using multiple loops. Then count each option. Example count($array['large']); " <?php if(!J2StoreOrdersHelper::isJSON(stripslashes($item->orderitem_attribute_names))): ?> <?php if (!empty($item->orderitem_attribute_names)) : ?> <span><?php echo $item->orderitem_attribute_names; ?></span> <?php endif; ?> <br /> <?php else: ?> <!-- since 3.1.0. Parse attributes that are saved in JSON format --> <?php if (!empty($item->orderitem_attribute_names)) : ?> <?php //first convert from JSON to array $registry = new JRegistry; $registry->loadString(stripslashes($item->orderitem_attribute_names), 'JSON'); $product_options = $registry->toObject(); ?> <?php foreach ($product_options as $option) : ?> - <small> <?php echo JText::_($option->name); ?>: <?php echo JText::_($option->value); ?> <?php echo count($item); ?> <?php if(isset($option->option_sku) && JString::strlen($option->option_sku) > 0):?> (<?php echo JText::_('J2STORE_SKU'); ?> : <?php echo $option->option_sku; ?>) <?php endif; ?> </small><br /> <?php endforeach; ?> <br/> <?php endif; ?> <?php endif; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.