Products
Title
Ingen forandringerPermalink
Ingen forandringerInnhold
| Old | New | ||
|---|---|---|---|
| 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 | $ | 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 | ``` |
Redigert av tim feb. 16 2025 kl 22:29