当前位置: 首页>>代码示例>>PHP>>正文


PHP ActiveRecordModel::getInstanceByIDIfExists方法代码示例

本文整理汇总了PHP中ActiveRecordModel::getInstanceByIDIfExists方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecordModel::getInstanceByIDIfExists方法的具体用法?PHP ActiveRecordModel::getInstanceByIDIfExists怎么用?PHP ActiveRecordModel::getInstanceByIDIfExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ActiveRecordModel的用法示例。


在下文中一共展示了ActiveRecordModel::getInstanceByIDIfExists方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 public function setUp()
 {
     parent::setUp();
     BusinessRuleController::clearCache();
     ActiveRecord::executeUpdate('DELETE FROM DeliveryZone');
     ActiveRecord::executeUpdate('DELETE FROM Tax');
     ActiveRecord::executeUpdate('DELETE FROM TaxRate');
     ActiveRecord::executeUpdate('DELETE FROM DiscountCondition');
     ActiveRecord::executeUpdate('DELETE FROM DiscountAction');
     ActiveRecord::executeUpdate('DELETE FROM Currency');
     $this->root = DiscountCondition::getRootNode();
     $this->usd = ActiveRecordModel::getInstanceByIDIfExists('Currency', 'USD');
     $this->usd->save();
     $this->user = User::getNewInstance('discount.condition@test');
     $this->user->save();
     $this->order = CustomerOrder::getNewInstance($this->user);
     $this->order->currency->set($this->usd);
     $this->order->save(true);
     $this->product1 = Product::getNewInstance(Category::getRootNode());
     $this->product1->isEnabled->set(true);
     $this->product1->setPrice('USD', 10);
     $this->product1->save();
     $this->product2 = Product::getNewInstance(Category::getRootNode());
     $this->product2->isEnabled->set(true);
     $this->product2->setPrice('USD', 20);
     $this->product2->save();
     ActiveRecordModel::getApplication()->getConfig()->setRuntime('INVENTORY_TRACKING', 'DISABLE');
 }
开发者ID:saiber,项目名称:livecart,代码行数:28,代码来源:DiscountConditionTest.php

示例2: 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);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:78,代码来源:ProductMassActionProcessor.php

示例3: getNextCustomerOrder

 public function getNextCustomerOrder()
 {
     if (!($data = $this->loadRecord('SELECT * FROM ' . $this->getTablePrefix() . 'orders WHERE customerID > 0'))) {
         return null;
     }
     $user = ActiveRecordModel::getInstanceByIDIfExists('User', $this->getRealId('User', $data['customerID'], false));
     if (!$user || !$user->isExistingRecord()) {
         return $this->getNextCustomerOrder();
     }
     $currCode = $data['currency_code'];
     if (!($currency = ActiveRecordModel::getInstanceByIDIfExists('Currency', $currCode, false))) {
         $currency = Currency::getNewInstance($currCode);
         $currency->save();
     }
     $order = CustomerOrder::getNewInstance($user);
     $order->currency->set($currency);
     $order->dateCompleted->set($data['order_time']);
     // products
     foreach ($this->getDataBySql('SELECT * FROM ' . $this->getTablePrefix() . 'ordered_carts WHERE orderID=' . $data['orderID']) as $item) {
         $product = null;
         // try to identify product by SKU
         preg_match('/\\[(.*)\\]/', $item['name'], $sku);
         if (isset($sku[1])) {
             $product = Product::getInstanceBySKU($sku[1]);
         }
         // if that doesn't work, then try to match the exact name
         if (!$product) {
             $productData = array_shift($this->getDataBySQL('SELECT productID FROM ' . $this->getTablePrefix() . 'products WHERE name="' . addslashes($item['name']) . '"'));
             if ($productData && is_array($productData)) {
                 $product = Product::getInstanceByID($this->getRealId('Product', $productData['productID']), Product::LOAD_DATA);
             }
         }
         if ($product) {
             $order->addProduct($product, $item['Quantity'], true);
             $orderedItem = array_shift($order->getItemsByProduct($product));
             $orderedItem->price->set($item['Price']);
         }
     }
     // addresses
     $order->shippingAddress->set($this->getUserAddress($data, 'shipping_'));
     $order->billingAddress->set($this->getUserAddress($data, 'billing_'));
     $order->status->set($this->getOrderStatus($data['statusID']));
     if ($order->status->get() == CustomerOrder::STATUS_SHIPPED) {
         $order->isPaid->set(true);
     }
     $order->rawData = $data;
     return $order;
 }
开发者ID:saiber,项目名称:www,代码行数:48,代码来源:ShopScriptImport.php

示例4: 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);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:saiber,项目名称:www,代码行数:61,代码来源:ProductMassActionProcessor.php


注:本文中的ActiveRecordModel::getInstanceByIDIfExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。