Shop_Manufacturer
The Shop_Manufacturer class represents a product manufacturer. This class has fields and methods for accessing a manufacturer name, address and contact information. Objects of this class are accessible through the $manufacturer field of the Shop_Product class. You can find examples of the class usage on the Displaying product manufacturer information, Creating the Manufacturer List Page and Manufacturer Details page articles.
Parent class: Db_ActiveRecord
Class fields
- $name - a manufacturer name
- $description - a manufacturer description
- $address - manufacturer street address
- $city - manufacturer city name
- $zip - manufacturer ZIP code
- $phone - phone number
- $fax - fax number
- $email - email address
- $url - website URL
- $country - a manufacturer country. An object of the Shop_Country class. This field can be NULL if a country was not specified in the manufacturer configuration form. If you need a simple and safe way to extract the manufacturer country name you can use the following code:
Country: <?= $product->manufacturer->columnValue('country') ?> - $state - a manufacturer state. An object of the Shop_CountryState class. This field can be NULL if a state was not specified in the manufacturer configuration form. If you need a simple and safe way to extract the manufacturer state name you can use the following code:
Country: <?= $product->manufacturer->columnValue('state') ?> - $logo - a collection of the manufacturer logo images. The collection always contain zero or one element. Each element in the collection is an object of the Db_File class.
- $url_name - the manufacturer's URL name.
Class methods
- logo_url($width, $height, $as_jpeg = true, $params = array()) - returns a relative URL of the manufacturer logo image thumbnail, or NULL if the logo was not uploaded. Use this method for displaying a manufacturer logo. The first and second parameters are thumbnail width and height correspondingly. You can use exact integer values, or word 'auto' for automatic image resizing. The $as_jpeg parameter allows you to generate PNG images with transparency support. By default the parameter value is TRUE and the method generates a JPEG image. Pass the FALSE value to the parameter to generate a PNG image. The $params array allows to pass parameters to image processing modules (which handle the core:onProcessImage event). The following line of code outputs a thumbnail of the manufacturer logo. The thumbnail width is 100 pixels, and thumbnail height is calculated by LemonStand to keep the original aspect ratio.
<img src="<?= h($product->manufacturer->logo_url(100, 'auto')) ?>"/>
- create() - creates an instance of the class.
- list_products([$options]) - returns a list of the manufacturer products. The result of this function is an object of the Shop_Product class. To obtain a collection of all manufacturer products call the find_all() methods of the method result.
$full_product_list = $manufacturer->list_products()->find_all()
The find_all() methods returns an object of the Db_DataCollection class, which you can use as a usual array.
You can use the result of the list_products() method for further processing, for example for paginating the category products list. Please read the Displaying a list of products article for the examples.
You can pass an array of options to the optional method parameter. The only currently supported options is the sorting . By default the product list is sorted by product name. You can products them by other field. Also, you can sort the product list by multiple fields.$product_list = $manufacturer->list_products(array( 'sorting'=>array('price', 'name') ))The supported fields you can sort the products are:- name - sort the product list by name
- price - sort the product list by the base price
- sku - sort the product list by SKU
- weight - sort the product list by weight
- width - sort the product list by width
- height - sort the product list by height
- depth - sort the product list by depth
- created_at - sort the product list by the product creation date
- rand() - allows to order products randomly
$product_list = $manufacturer->list_products(array( 'sorting'=>array('price desc') )) - list_categories() - returns a list of categories the manufacturer products belong to. Returns the Db_DataCollection object. Each item in the collection is an object of the Shop_Category class.
Displaying a list of manufacturers
You can use the following code for displaying a list of manufacturers on a page:
<? $manufacturers = Shop_Manufacturer::create()->order('name')->find_all(); ?>
<ul>
<? foreach ($manufacturers as $manufacturer): ?>
<li><?= h($manufacturer->name) ?></li>
<? endforeach ?>
</ul>Alternatively you can use the shop:manufacturers action for creating the Manufacturer List Page.
Next: shop:cart
Previous: Shop_ExtraOption
Return to Reference


Comments
allibubba
Saturday, May 01, 2010if you create url's when you set up new manufacturer, like: my_shop_name, to access that in your list, use: $manufacturer->url_name,
this way you will have a url like:
/vendor/my_shop_name/
rather than:
/vendor/1/
Add your comment
Loading form...