hope someone can help me.
I try to write a Import Script for Articles in my Shopsystem.
For this edit the basic Code from the Wiki of the Shopsystem.
Here look
$updateArticle = array(
'configuratorSet' => array(
'groups' => array(
array(
'name' => 'Farben',
'options' => $farbenarray
),
array(
'name' => 'Größe',
'options' => $sizearray
),
)
),
'taxId' => 1,
'variants' => array(
array(
'isMain' => true,
'number' => 'turn',
'inStock' => 15,
'additionaltext' => 'L / Black',
'configuratorOptions' => array(
array('group' => 'Size', 'option' => 'L'),
array('group' => 'Color', 'option' => 'Black'),
),
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => 1999,
),
)
),
array(
'isMain' => false,
'number' => 'turn.1',
'inStock' => 15,
'additionnaltext' => 'S / Black',
'configuratorOptions' => array(
array('group' => 'Size', 'option' => 'S'),
array('group' => 'Color', 'option' => 'Black'),
),
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => 999,
),
)
),
array(
'isMain' => false,
'number' => 'turn.2',
'inStock' => 15,
'additionnaltext' => 'S / Red',
'configuratorOptions' => array(
array('group' => 'Size', 'option' => 'S'),
array('group' => 'Color', 'option' => 'Red'),
),
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => 999,
),
)
),
array(
'isMain' => false,
'number' => 'turn.3',
'inStock' => 15,
'additionnaltext' => 'XL / Red',
'configuratorOptions' => array(
array('group' => 'Size', 'option' => 'XL'),
array('group' => 'Color', 'option' => 'Red'),
),
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => 999,
),
)
)
)
);
Now i wan't to replace all the Variant Array with a While request.
Replace all like this
array(
'isMain' => true,
'number' => 'turn',
'inStock' => 15,
'additionaltext' => 'L / Black',
'configuratorOptions' => array(
array('group' => 'Size', 'option' => 'L'),
array('group' => 'Color', 'option' => 'Black'),
),
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => 1999,
),
)
),
With a like a request like that ( i know thats don't work but i hope you understand what i like to do)
if ($resultat = $db->query('SELECT * FROM cache_article ORDER by id WHERE artikelnummer = "'.$herstellernummer.'"')) {
while($daten = $resultat->fetch_object() ){
// WHILE THE ARRAY CODES
array(
'isMain' => true,
'number' => $daten->artikelnummer,
'inStock' => 1,
'additionaltext' => ''.$daten->size.' / '.$daten->color.'',
'configuratorOptions' => array(
array('group' => 'Size', 'option' => $daten->size),
array('group' => 'Color', 'option' => $daten->color),
),
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => $daten->price,
),
)
),
// END THE ARRAY Codes
}
}
How i can do that correct so that works?
Please give me a Example for the request and how i can integrate that.
Sorry for my bad english! -.-
Thank You
I think i understand you.What you need is to store the generated arrays inside another, like this:
while(...
$arrayOfArrays[] = Array(...
That is explained here.
Basically $variable[] appends an element to the end of the array, but if the array doesn't exists then it creates it first.
Related
I am creating custom report that following this script. It works fine, but I need to know how to get the all ordered product attributes.
include_once(WC()->plugin_path().'/includes/admin/reports/class-wc-admin-report.php');
$wc_report = new WC_Admin_Report();
$sold_products = $wc_report->get_order_report_data( array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id'
),
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'quantity'
),
'_line_subtotal' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'gross'
),
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'gross_after_discount'
)
),
'where' => array(
array(
'key' => 'order_items.order_item_name',
'value' => '%shirt%',
'operator' => 'LIKE',
),
),
'group_by' => 'order_item_name',
'query_type' => 'get_results',
'limit' => 20,
'order_status' => array( 'completed', 'processing' ),
) );
foreach($sold_products as $product){
//how to we get the attributes of each sold product?
}
}
I can see attributes are stored in _woocommerce_order_itemmeta table, I can use the 'data' above to get it one by one. But the thing is if some attributes only applied to certain product, which will caused the query above searched no result. So it would be better to get all of the ordered item attributes at once.
I have an array that has a value with multiple options that is broken down into it's own array. One of those values I want to populate with a loop. Is this possible with the ; in the forloop I would think it would break. What is the best way to accomplish this request?
array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array(
for ($x=0; $x<=10; $x++){
array('name' => __($x , 'title'), 'value' => $x)
}
)
),
Here is the complete array outside of what I posted:
$meta_boxes[] = array(
'id' => 'januas_speakers',
'title' => __('Ensemble', 'januas'),
'pages' => array('ja-event'),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __('Visible', 'januas'),
'desc' => __('Select Yes to show the box in the event page, No to hide it.', 'januas'),
'id' => 'januas_speakers_visible',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => __('Position', 'januas'),
'desc' => __('Select the preferred position for the box.', 'januas'),
'id' => 'januas_speakers_position',
'type' => 'select',
'options' => array(
array('name' => __('Main', 'januas'), 'value' => 'main'),
array('name' => __('Sidebar', 'januas'), 'value' => 'sidebar'),
)
),
array(
'name' => __('Order', 'januas'),
'desc' => __('Insert the box order (ex: 1).', 'januas'),
'id' => 'januas_speakers_order',
'std' => 1,
'type' => 'text_small'
),
array(
'name' => __('Show Title', 'januas'),
'desc' => __('Select Yes to show the box title, No to hide it.', 'januas'),
'id' => 'januas_speakers_showtitle',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => __('Show in Top menu', 'januas'),
'desc' => __('Select Yes to show the menu item in the event page top menu, No to hide it.', 'januas'),
'id' => 'januas_speakers_showinmenu',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => '',
'desc' => '',
'id' => 'januas_images_gallery',
'type' => 'image_gallery'
),
array(
'name' => __('Ensemble List', 'januas'),
'desc' => 'Select the ensemble memebers for this event.',
'id' => 'januas_speakers_completelist',
'type' => 'checkbox',
'options' => array_map(function ($x) {
return array(
'name' => __($x, 'januas'),
'value' => $x,
);
}, range(0,11))
),
array(
'name' => __('Display order', 'januas'),
'desc' => '',
'id' => 'januas_speakers_speakersorder',
'type' => 'event_speakers'
),
array(
'name' => '',
'desc' => '',
'id' => 'januas_speakers_backtotop',
'type' => 'backtotop'
)
),
);
You could use array_map:
array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array_map(function ($x) {
return array(
'name' => __($x, 'title'),
'value' => $x,
);
}, range(0,11))
),
You should use array_push
$a = array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array()
);
for ($x=0; $x<=10; $x++){
array_push( $a['options'], array('name' => __($x , 'title'), 'value' => $x) );
}
print_r($a);
Do you need to run the loop inside of options? How about this approach.
$foo = array();
for ($x=0;$x<10;$x++)
$foo[] = $x;
$bar = array(
'name' => 'hello',
'options' => $foo
);
print_r($bar);
https://eval.in/54925
I'm having an issue with Paginator->settings. For some reason, recursive is not working. Any ideas? I've tried setting $this->Cheese->recursive = 2 and haven't had any luck.
$this->Cheese->recursive = 2;
$this->Paginator->settings = array(
'CheeseCheckin' => array(
'fields' => array('id','created','comment','location','rating','short_url_hash','foursquare_id'),
'conditions'=>array(
'CheeseCheckin.cheese_id' => $id
),
'contain' => array(
'Cheese'=>array(
'fields' => array('id','name','created','modified','attachment_id'),
'Attachment' => array(
'fields' => array('id','name','ext','path')
)
),
'CheeseProducer' => array(
'fields' => array('name','created', 'id','attachment_id')
),
'User' => array(
'fields' => $this->userFields,
'Attachment' => array(
'fields'=>array('id','name','ext','path')
),
'StateRegion' => array(
'fields'=>array('name','code')
),
'Country' => array(
'fields'=>array('name','code')
)
),
'Place' => array(
'fields'=>array('id','name')
),
'UserAttachment' => array(
'fields' => array('id','ext','name','path')
)
),
'page' => $page,
'order' => array('CheeseCheckin.created' => 'DESC'),
'limit' => $limit,
'recursive' => 2
)
);
debug($this->Paginator->paginate('CheeseCheckin'));
The results look like:
array(
(int) 0 => array(
'CheeseCheckin' => array(
'id' => '62',
'created' => '2013-09-06 13:34:44',
'comment' => 'This is a test',
'location' => null,
'rating' => '4',
'short_url_hash' => '18ARMkq',
'foursquare_id' => '40d77680f964a5205d011fe3'
),
'UserAttachment' => array(
'id' => null,
'ext' => null,
'name' => null,
'path' => null
),
'User' => array(
'id' => '1',
'username' => '...',
'name' => 'Rob',
'profile_image_url' => '...',
'active' => '1',
'email' => 'robksawyer#gmail.com',
'private' => false,
'attachment_id' => '616',
'country_id' => '228',
'state_region_id' => '48'
),
'Cheese' => array(
'id' => '379',
'name' => 'Party In a Jar',
'created' => '2012-10-05 16:57:04',
'modified' => '2013-09-13 02:12:27',
'attachment_id' => '460'
),
'CheeseProducer' => array(
'name' => 'Alsea Acre Goat Cheese',
'created' => '2012-10-05 16:50:51',
'id' => '43',
'attachment_id' => null
),
'Place' => array(
'id' => null,
'name' => null
)
)
)
Fixed the issue. I just had to add user_id, attachment_id, etc. to the fields array.
I am using the following code to add custom meta boxes to the admin of my custom post types.
<?php
$prefix = '_myType_';
global $meta_boxes;
$meta_boxes = array();
$meta_boxes[] = array(
'id' => 'myType',
'title' => 'myType Data',
'pages' => array( 'myType' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => 'Starts',
'id' => "{$prefix}starts",
'type' => 'date',
'js_options' => array(
'appendText' => '(yyyy-mm-dd)',
'dateFormat' => 'yy-mm-dd',
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
),
array(
'name' => 'Ends',
'id' => "{$prefix}ends",
'type' => 'date',
'js_options' => array(
'appendText' => '(yyyy-mm-dd)',
'dateFormat' => 'yy-mm-dd',
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
),
)
);
function YOUR_PREFIX_register_meta_boxes()
{
if ( !class_exists( 'RW_Meta_Box' ) )
return;
global $meta_boxes;
foreach ( $meta_boxes as $meta_box )
{
new RW_Meta_Box( $meta_box );
}
}
add_action( 'admin_init', 'YOUR_PREFIX_register_meta_boxes' );
I have quite a few fields and I need a way to group the items together with something like a hr tag.
And for some reason i thought this would work
array(
'id' => 'box_1_hr',
'name' => 'box_1_hr',
'type' => 'hr',
'options' => array(
'width' => '100%',
'color' => '#DFDFDF'
)
),
But it didnt!
Doesnt anyone have any ideas if this can be done?
Thanks
I have this multidimensional assoc $modules array in cakephp 2.2.3:
array(
'type1' => array(
(int) 0 => array(
'name' => 'name16',
'type' => '1',
'category' => 'categoryC',
'zone' => 'zone1'
),
(int) 1 => array(
'name' => 'name17',
'type' => '1',
'category' => 'categoryB',
'zone' => 'zone1'
),
(int) 2 => array(
'name' => 'name18',
'type' => '1',
'category' => 'categoryA',
'zone' => 'zone3'
),
(int) 3 => array(
'name' => 'name19',
'type' => '1',
'category' => 'categoryC',
'zone' => 'zone3'
),
(int) 4 => array(
'name' => 'name22',
'type' => '1',
'category' => 'categoryA',
'zone' => 'zone2'
)
),
'type2' => array(
(int) 0 => array(
'name' => 'name1',
'type' => '2',
'category' => 'categoryB',
'zone' => 'zone2'
),
(int) 1 => array(
'name' => 'name2',
'type' => '2',
'category' => 'categoryB',
'zone' => 'zone2'
),
(int) 2 => array(
'name' => 'name3',
'type' => '2',
'category' => 'categoryA',
'zone' => 'zone1'
),
(int) 3 => array(
'name' => 'name4',
'type' => '2',
'category' => 'categoryC',
'zone' => 'zone3'
),
(int) 4 => array(
'name' => 'name5',
'type' => '2',
'category' => 'categoryA',
'zone' => 'zone3'
)
)
)
and I want to rearrange it like
array(
'zone1' => array(
'type1' => array(
(int) 0 => array(
'name' => 'name17',
'type' => '1',
'category' => 'categoryB'
),
(int) 1 => array(
'name' => 'name16',
'type' => '1',
'category' => 'categoryC'
)
),
'type2' => array(
(int) 0 => array(
'name' => 'name3',
'type' => '2',
'category' => 'categoryA'
)
)
),
'zone2' => array(
'type1' => array(
(int) 0 => array(
'name' => 'name22',
'type' => '1',
'category' => 'categoryA'
)
),
'type2' => array(
(int) 0 => array(
'name' => 'name1',
'type' => '2',
'category' => 'categoryB'
),
(int) 1 => array(
'name' => 'name2',
'type' => '2',
'category' => 'categoryB'
)
)
),
'zone3' => array(
'type1' => array(
(int) 0 => array(
'name' => 'name18',
'type' => '1',
'category' => 'categoryA'
),
(int) 0 => array(
'name' => 'name19',
'type' => '1',
'category' => 'categoryC'
)
),
'type2' => array(
(int) 0 => array(
'name' => 'name5',
'type' => '2',
'category' => 'categoryA'
),
(int) 1 => array(
'name' => 'name4',
'type' => '2',
'category' => 'categoryC'
)
)
)
)
where 'category' should be sorted alphabetically within each parent 'type'
I tried with
$modules = Hash::combine($modules, '{n}', '{n}.{n}', '{s}.{s}.{n}.zone');
but with no success. I guess I'm not using Hash::combine as I should...
Thanks, Marius
Just use a foreach inside a foreach to walk through your array and construct a new one based on your preference.