示例#1
0
listProducts($products);
// query with filter
echo ' -> get all products with a purchase cost of at least 1000' . "\n";
$filter = new DFC(ProductModel::FIELD_PURCHASE_COST, 1000, DFC::NOT | DFC::SMALLER);
$products = ProductModel::findByFilter($db, $filter, true, $sort);
listProducts($products);
echo ' -> get all products with a purchase cost smallther than 1000 and the description containg Computer' . "\n";
$filter = array(new DFC(ProductModel::FIELD_PURCHASE_COST, 1000, DFC::SMALLER), new DFC(ProductModel::FIELD_DESCRIPTION, 'Computer', DFC::CONTAINS));
$products = ProductModel::findByFilter($db, $filter);
listProducts($products);
// query with SQL
$sql = "SELECT * FROM PRODUCT WHERE DESCRIPTION LIKE '%Sound%'";
echo ' -> get by SQL: ' . $sql . "\n";
$products = ProductModel::findBySql($db, $sql);
listProducts($products);
// insert new product
$product = new ProductModel();
$product->setProductId(123)->setManufacturerId(123)->setProductCode('HW')->setPurchaseCost(1234567890)->setQuantityOnHand(1)->setMarkup(1234567891)->setAvailable('TRUE')->setDescription('Test Product');
$product->insertIntoDatabase($db);
// update product
$product->setPurchaseCost(100);
$product->setMarkup(120);
$product->setQuantityOnHand(200);
// get changed fields
var_dump($product->getFieldsValuesChanged());
$product->updateToDatabase($db);
// delete product
$product->deleteFromDatabase($db);
// dom functions
echo $product->toDOM()->saveXML();
var_dump(ProductModel::fromDOMDocument($product->toDOM()));