本文整理汇总了PHP中ActiveRecordModel::getInstanceByIdIfExists方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecordModel::getInstanceByIdIfExists方法的具体用法?PHP ActiveRecordModel::getInstanceByIdIfExists怎么用?PHP ActiveRecordModel::getInstanceByIdIfExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecordModel
的用法示例。
在下文中一共展示了ActiveRecordModel::getInstanceByIdIfExists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCategory
public function addCategory()
{
$product = Product::getInstanceByID($this->request->get('id'), ActiveRecord::LOAD_DATA, array('Category'));
$category = Category::getInstanceByID($this->request->get('categoryId'), ActiveRecord::LOAD_DATA);
// check if the product is not assigned to this category already
$relation = ActiveRecordModel::getInstanceByIdIfExists('ProductCategory', array('productID' => $product->getID(), 'categoryID' => $category->getID()));
if ($relation->isExistingRecord() || $product->category->get() === $category) {
return new JSONResponse(false, 'failure', $this->translate('_err_already_assigned'));
}
$relation->save();
return new JSONResponse(array('data' => $relation->toFlatArray()));
}
示例2: getNextCurrency
public function getNextCurrency()
{
if (!$this->currenciesTruncated) {
ActiveRecord::executeUpdate('DELETE FROM Currency');
$this->currenciesTruncated = true;
}
if (!($data = $this->loadRecord('SELECT * FROM ' . $this->getTablePrefix() . 'currencies'))) {
return null;
}
$curr = ActiveRecordModel::getInstanceByIdIfExists('Currency', $data['code']);
$curr->pricePrefix->set($data['symbol_left']);
$curr->priceSuffix->set($data['symbol_right']);
$curr->rate->set($data['value']);
$curr->lastUpdated->set($data['last_updated']);
$curr->isEnabled->set(true);
if ($this->getConfigValue('DEFAULT_CURRENCY') == $curr->getID()) {
$curr->isDefault->set(true);
}
return $curr;
}
示例3: processRecord
protected function processRecord(Product $product)
{
$act = $this->getAction();
$field = $this->getField();
if ('manufacturer' == $act) {
$product->manufacturer->set($this->params['manufacturer']);
} else {
if ('price' == $act) {
$product->setPrice($this->params['baseCurrency'], $this->params['price']);
} else {
if (in_array($act, array('inc_price', 'multi_price', 'div_price'))) {
$actions = array('inc_price' => 'increasePriceByPercent', 'multi_price' => 'multiplyPrice', 'div_price' => 'dividePrice');
$action = $actions[$act];
$pricing = $product->getPricingHandler();
foreach ($this->params['currencies'] as $currency) {
if ($pricing->isPriceSet($currency)) {
$p = $pricing->getPrice($currency);
$p->{$action}($this->params['inc_price_value'], $this->params['inc_quant_price']);
$p->save();
}
}
} else {
if ('inc_stock' == $act) {
$product->stockCount->set($product->stockCount->get() + $this->request->get($act));
} else {
if ('addRelated' == $act) {
$product->addRelatedProduct($this->params['relatedProduct']);
} else {
if ('copy' == $act) {
$cloned = clone $product;
$cloned->category->set($this->params['category']);
$cloned->save();
} else {
if ('addCat' == $act) {
// check if the product is not assigned to this category already
$relation = ActiveRecordModel::getInstanceByIdIfExists('ProductCategory', array('productID' => $product->getID(), 'categoryID' => $this->params['category']->getID()));
if (!$relation->isExistingRecord() && $product->category->get() !== $category) {
$relation->save();
}
} else {
if ('theme' == $act) {
$instance = CategoryPresentation::getInstance($product);
$instance->theme->set($this->params['theme']);
$instance->save();
} else {
if ('shippingClass' == $act) {
$product->shippingClass->set(ActiveRecordModel::getInstanceByIDIfExists('ShippingClass', $this->params['shippingClass'], false));
} else {
if ('taxClass' == $act) {
$product->taxClass->set(ActiveRecordModel::getInstanceByIDIfExists('TaxClass', $this->params['taxClass'], false));
} else {
if (substr($act, 0, 13) == 'set_specField') {
$this->params['request']->remove('manufacturer');
$product->loadRequestData($this->params['request']);
} else {
if (substr($act, 0, 16) == 'remove_specField') {
$this->params['request']->remove('manufacturer');
if ($this->params['field']->isMultiValue->get()) {
// remove only selected multi-select options
$product->loadRequestData($this->params['request']);
} else {
$product->removeAttribute($this->params['field']);
}
} else {
parent::processRecord($product);
}
}
}
}
}
}
}
}
}
}
}
}
}
示例4: getNextLanguage
public function getNextLanguage()
{
if ($this->defLang) {
return null;
}
// default language is set to English
$id = 'en';
if (!($lang = ActiveRecordModel::getInstanceByIdIfExists('Language', $id, false))) {
$lang = ActiveRecordModel::getNewInstance('Language');
$lang->setID($id);
$lang->isEnabled->set(true);
$lang->isDefault->set(true);
}
$this->defLang = $lang->getID();
return $lang;
}
示例5: processRecord
protected function processRecord(Product $product)
{
$act = $this->getAction();
$field = $this->getField();
if ('manufacturer' == $act) {
$product->manufacturer->set($this->params['manufacturer']);
} else {
if ('price' == $act) {
$product->setPrice($this->params['baseCurrency'], $this->params['price']);
} else {
if ('inc_price' == $act) {
$pricing = $product->getPricingHandler();
foreach ($this->params['currencies'] as $currency) {
if ($pricing->isPriceSet($currency)) {
$p = $pricing->getPrice($currency);
$p->increasePriceByPercent($this->params['inc_price_value'], $this->params['inc_quant_price']);
$p->save();
}
}
} else {
if ('inc_stock' == $act) {
$product->stockCount->set($product->stockCount->get() + $this->request->get($act));
} else {
if ('addRelated' == $act) {
$product->addRelatedProduct($this->params['relatedProduct']);
} else {
if ('copy' == $act) {
$cloned = clone $product;
$cloned->category->set($this->params['category']);
$cloned->save();
} else {
if ('addCat' == $act) {
// check if the product is not assigned to this category already
$relation = ActiveRecordModel::getInstanceByIdIfExists('ProductCategory', array('productID' => $product->getID(), 'categoryID' => $this->params['category']->getID()));
if (!$relation->isExistingRecord() && $product->category->get() !== $category) {
$relation->save();
}
} else {
if ('theme' == $act) {
$instance = CategoryPresentation::getInstance($product);
$instance->theme->set($this->params['theme']);
$instance->save();
} else {
if ('shippingClass' == $act) {
$product->shippingClass->set(ActiveRecordModel::getInstanceByIDIfExists('ShippingClass', $this->params['shippingClass'], false));
} else {
if ('taxClass' == $act) {
$product->taxClass->set(ActiveRecordModel::getInstanceByIDIfExists('TaxClass', $this->params['taxClass'], false));
} else {
parent::processRecord($product);
}
}
}
}
}
}
}
}
}
}
}