Products

Titlu

Fără modificări

Permalink

Fără modificări

Conținut

OldNew
62## Entity Object 62## Entity Object
63 63
64```php 64```php
65// Initiate a new product
65$product = new ent_product(); 66$product = new ent_product();
66$product->data['name'] = ['en' => 'Yellow Duck']; 67
67$product->data['prices'] = ['USD' => 9.99]; 68// Set english name
69$product->data['name']['en'] = 'Yellow Duck';
70
71// Set dollar price
72$product->data['prices']['USD'] = 9.99;
73
74// Add an attribute
75$product->data['attributes'][] = [
76 'group_id' => 11,
77 'value_id' => 0,
78 'custom_value' => 'Lorem ipsum',
79];
80
68$product->save(); 81$product->save();
69``` 82```
70 83
79## Database Query 92## Database Query
80 93
81```php 94```php
82$query = database::query( 95$product = database::query(
83 "select p.id, pi.name, pp.`USD` as price from ". DB_TABLE_PREFIX ."products p 96 "select p.id, pi.name, pp.`USD` as price from ". DB_TABLE_PREFIX ."products p
84 left join ". DB_TABLE_PREFIX ."products_info pi on (pi.product_id = p.id and pi.language_code = 'en') 97 left join ". DB_TABLE_PREFIX ."products_info pi on (pi.product_id = p.id and pi.language_code = 'en')
85 left join ". DB_TABLE_PREFIX ."products_prices pp on (pp.product_id = p.id) 98 left join ". DB_TABLE_PREFIX ."products_prices pp on (pp.product_id = p.id)
86 where p.id = ". (int)$product_id ." 99 where p.id = ". (int)$product_id ."
87 limit 1;" 100 limit 1;"
88); 101)->fetch();
89
90$product = database::fetch($query);
91```102```

Edited by tim on 16 feb. 2025 at 22:29

This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.