本文整理汇总了PHP中ActiveRecord::objectExists方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::objectExists方法的具体用法?PHP ActiveRecord::objectExists怎么用?PHP ActiveRecord::objectExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::objectExists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateAndRetrieve
public function testCreateAndRetrieve()
{
// set up currency
if (ActiveRecord::objectExists('Currency', 'USD')) {
$this->usd = Currency::getInstanceByID('USD', Currency::LOAD_DATA);
} else {
$this->usd = Currency::getNewInstance('USD');
$this->usd->setAsDefault();
$this->usd->save();
}
$products = array();
for ($k = 0; $k <= 2; $k++) {
$products[$k] = Product::getNewInstance($this->root);
$products[$k]->setPrice($this->usd, $k + 1);
$products[$k]->save();
$bundled = ProductBundle::getNewInstance($this->container, $products[$k]);
$bundled->save();
}
$list = ProductBundle::getBundledProductSet($this->container);
$this->assertEqual($list->size(), count($products));
foreach ($list as $index => $item) {
$this->assertSame($item->relatedProduct->get(), $products[$index]);
}
$this->assertEqual(ProductBundle::getTotalBundlePrice($this->container, $this->usd), 6);
}
示例2: setUpCurrency
/**
* !Running tests not involving initOrder() method will not recreate Currency,
* but setUp() method is wiping all Currecy records,
*
* Store frontend is not working without Currency object
*
* As workround this method can be called from test suite to recreate Currency
*
* @todo: reorganize tests to call DELETE FROM Currency only when setUpCurrency() method is called.
*
*/
protected function setUpCurrency()
{
if (ActiveRecord::objectExists('Currency', 'USD')) {
$this->usd = Currency::getInstanceByID('USD', Currency::LOAD_DATA);
} else {
$this->usd = Currency::getNewInstance('USD');
$this->usd->setAsDefault();
$this->usd->save();
}
}
示例3: setConfig
public function setConfig()
{
if (!$this->buildConfigValidator()->isValid()) {
return new ActionRedirectResponse('install', 'config');
}
Language::deleteCache();
// site name
$this->config->setValueByLang('STORE_NAME', $this->request->get('language'), $this->request->get('name'));
$this->config->save();
ClassLoader::import('application.model.Currency');
// create currency
if (ActiveRecord::objectExists('Currency', $this->request->get('curr'))) {
$currency = Currency::getInstanceByID($this->request->get('curr'), Currency::LOAD_DATA);
} else {
$currency = ActiveRecord::getNewInstance('Currency');
$currency->setID($this->request->get('curr'));
$currency->isEnabled->set(true);
$currency->isDefault->set(true);
$currency->save(ActiveRecord::PERFORM_INSERT);
}
ClassLoader::import('application.model.system.Language');
// create language
if (ActiveRecord::objectExists('Language', $this->request->get('language'))) {
$language = Language::getInstanceByID($this->request->get('language'), Language::LOAD_DATA);
} else {
$language = ActiveRecord::getNewInstance('Language');
$language->setID($this->request->get('language'));
$language->save(ActiveRecord::PERFORM_INSERT);
$language->isEnabled->set(true);
$language->isDefault->set(true);
$language->save();
}
// set root category name to "LiveCart"
ClassLoader::import('application.model.category.Category');
$root = Category::getInstanceById(Category::ROOT_ID, Category::LOAD_DATA);
$root->setValueByLang('name', $language->getID(), 'LiveCart');
$root->save();
// create a default shipping service
ClassLoader::import('application.model.delivery.DeliveryZone');
ClassLoader::import('application.model.delivery.ShippingService');
ClassLoader::import('application.model.delivery.ShippingRate');
$service = ShippingService::getNewInstance(DeliveryZone::getDefaultZoneInstance(), 'Default Service', ShippingService::SUBTOTAL_BASED);
$service->save();
$rate = ShippingRate::getNewInstance($service, 0, 100000);
$rate->flatCharge->set(10);
$rate->save();
// create a couple of blank static pages
ClassLoader::import('application.model.staticpage.StaticPage');
$page = StaticPage::getNewInstance();
$page->setValueByLang('title', $language->getID(), 'Contact Info');
$page->setValueByLang('text', $language->getID(), 'Enter your contact information here');
$page->menu->set(array('INFORMATION' => true));
$page->save();
$page = StaticPage::getNewInstance();
$page->setValueByLang('title', $language->getID(), 'Shipping Policy');
$page->setValueByLang('text', $language->getID(), 'Enter your shipping rate & policy information here');
$page->menu->set(array('INFORMATION' => true));
$page->save();
// create an example site news post
ClassLoader::import('application.model.sitenews.NewsPost');
$news = ActiveRecordModel::getNewInstance('NewsPost');
$news->setValueByLang('title', $language->getID(), 'Our store is open');
$news->setValueByLang('text', $language->getID(), 'Powered by LiveCart software, we have gone live! Of course, we will have to go to <a href="../backend">the backend area</a> and add some categories and products first...');
$news->setValueByLang('moreText', $language->getID(), 'Do not forget to delete this post when you actually go live :)');
$news->isEnabled->set(true);
$news->save();
return new ActionRedirectResponse('install', 'finish');
}
示例4: importInstance
public function importInstance($record, CsvImportProfile $profile)
{
$this->className = 'Product';
$impReq = new Request();
$defLang = $this->application->getDefaultLanguageCode();
$references = array('DefaultImage' => 'ProductImage', 'Manufacturer', 'ShippingClass', 'TaxClass');
$cat = $this->getCategory($profile, $record);
$extraCategories = null;
$fields = $profile->getSortedFields();
if (isset($fields['Categories']['ExtraCategories'])) {
$extraCategories = explode('; ', $record[$fields['Categories']['ExtraCategories']]);
}
if (isset($fields['Product']) && $cat) {
$product = null;
if (isset($fields['Product']['ID']) && !empty($record[$fields['Product']['ID']])) {
$id = $record[$fields['Product']['ID']];
if (ActiveRecord::objectExists('Product', $id)) {
$product = Product::getInstanceByID($id, Product::LOAD_DATA, $references);
}
} else {
if (isset($fields['Product']['sku']) && !empty($record[$fields['Product']['sku']])) {
$product = Product::getInstanceBySku($record[$fields['Product']['sku']], $references);
}
}
if ($product && $product->getID()) {
$this->registerImportedID($product->getID());
}
if (!$product && 'update' == $this->options['action'] || $product && 'add' == $this->options['action']) {
return false;
}
if ($product) {
$product->loadSpecification();
$product->loadPricing();
} else {
if ($cat instanceof Category) {
$product = Product::getNewInstance($cat);
} else {
$product = $cat->createChildProduct();
}
$product->isEnabled->set(true);
}
// product information
$impReq->clearData();
foreach ($profile->getFields() as $csvIndex => $field) {
$column = $field['name'];
$params = $field['params'];
if (!isset($record[$csvIndex]) || empty($column)) {
continue;
}
$value = $record[$csvIndex];
list($className, $field) = explode('.', $column, 2);
if (isset($params['language'])) {
$lang = $params['language'];
if ($lang != $defLang) {
$field .= '_' . $lang;
}
}
if ($value) {
if ('Product.parentID' == $column) {
$product->parent->set();
continue;
}
if ('Product.parentSKU' == $column) {
$product->parent->set(Product::getInstanceBySKU($value));
continue;
}
}
if ('Product.taxClass' == $column) {
$product->taxClass->set(TaxClass::findByName($value));
}
if ('Product.shippingClass' == $column) {
$product->shippingClass->set(ShippingClass::findByName($value));
}
if ('Product' == $className) {
if ('shippingWeight' == $field) {
if ($this->application->getConfig()->get('UNIT_SYSTEM') == 'ENGLISH') {
$value = $value / 0.45359237;
}
}
if ('shippingWeight' == $field && $product->parent->get()) {
$value = $this->setChildSetting($product, 'weight', $value);
}
$impReq->set($field, $value);
} else {
if ('Manufacturer' == $className) {
$impReq->set('manufacturer', $value);
} else {
if ('ProductPrice.price' == $column) {
if ($product->parent->get()) {
$value = $this->setChildSetting($product, 'price', $value);
}
$value = preg_replace('/,([0-9]{3})/', '\\1', $value);
$value = (double) preg_replace('/[^\\.0-9]/', '', str_replace(',', '.', $value));
$currency = isset($params['currency']) ? $params['currency'] : $this->application->getDefaultCurrencyCode();
$quantityLevel = isset($params['quantityLevel']) ? $params['quantityLevel'] : '';
$group = isset($params['group']) ? $params['group'] : '';
$price = $product->getPricingHandler()->getPriceByCurrencyCode($currency);
$product->getPricingHandler()->setPrice($price);
if ($group || $quantityLevel) {
if ($value > 0) {
//.........这里部分代码省略.........
示例5: exists
/**
* This method is checking if SpecField record with passed id exist in the database
*
* @param int $id Record id
* @return boolean
*/
public static function exists($id)
{
return ActiveRecord::objectExists(__CLASS__, (int) $id);
}