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


PHP Product::getNewInstance方法代码示例

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


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

示例1: testAvailability

 public function testAvailability()
 {
     $this->config->setRuntime('INVENTORY_TRACKING', 'DISABLE');
     $product1 = Product::getNewInstance($this->root);
     $product1->save();
     $product2 = Product::getNewInstance($this->root);
     $product2->save();
     ProductBundle::getNewInstance($this->container, $product1)->save();
     ProductBundle::getNewInstance($this->container, $product2)->save();
     // bundle container not enabled
     $this->assertFalse($this->container->isAvailable());
     $this->container->isEnabled->set(true);
     $this->assertTrue($this->container->isAvailable());
     // turn on inventory tracking
     $this->config->setRuntime('INVENTORY_TRACKING', 'ENABLE_AND_HIDE');
     $product1->stockCount->set(2);
     $product1->save();
     $product2->stockCount->set(2);
     $product2->save();
     $this->assertTrue($this->container->isAvailable());
     // remove inventory for one product
     $product2->stockCount->set(0);
     $product2->save();
     $this->assertFalse($this->container->isAvailable());
 }
开发者ID:saiber,项目名称:livecart,代码行数:25,代码来源:ProductBundleTest.php

示例2: setUp

 public function setUp()
 {
     parent::setUp();
     $this->product = Product::getNewInstance(Category::getRootNode(), 'test');
     $this->product->save();
     $this->user = User::getNewInstance('sdfsdfsd@ProductRatingTest.com');
     $this->user->save();
 }
开发者ID:saiber,项目名称:livecart,代码行数:8,代码来源:ProductReviewTest.php

示例3: setUp

 public function setUp()
 {
     parent::setUp();
     $this->product = Product::getNewInstance($this->rootCategory, 'test');
     $this->product->save();
     $this->group = ProductFileGroup::getNewInstance($this->product);
     $this->group->save();
     // create temporary file
     file_put_contents($this->tmpFilePath, $this->fileBody);
 }
开发者ID:saiber,项目名称:livecart,代码行数:10,代码来源:ProductFileTest.php

示例4: setUp

 public function setUp()
 {
     parent::setUp();
     // create a product without attributes
     $this->product = Product::getNewInstance($this->category, 'test');
     $this->product->setValueByLang("name", "en", "TEST_PRODUCT");
     $this->product->save();
     $this->productAutoIncrementNumber = $this->product->getID();
     for ($k = 1; $k < 4; $k++) {
         $currency = Currency::getNewInstance($k . 'zz');
         $currency->save();
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:13,代码来源:ProductPricingTest.php

示例5: setUp

 public function setUp()
 {
     parent::setUp();
     ActiveRecordModel::executeUpdate('DELETE FROM ProductRatingType');
     $this->controller = new ProductController(self::getApplication());
     $this->product = Product::getNewInstance(Category::getRootNode());
     $this->product->isEnabled->set(true);
     $this->product->save();
     $this->request->set('id', $this->product->getID());
     self::getApplication()->getConfig()->set('ENABLE_REVIEWS', true);
     self::getApplication()->getConfig()->set('ENABLE_ANONYMOUS_RATINGS', true);
     self::getApplication()->getConfig()->set('REVIEWS_WITH_RATINGS', false);
 }
开发者ID:saiber,项目名称:livecart,代码行数:13,代码来源:ProductControllerTest.php

示例6: testContaining

 public function testContaining()
 {
     $root = Category::getRootNode();
     $list = ProductList::getNewInstance($root);
     $list->save();
     $product = Product::getNewInstance($root);
     $product->save();
     $list->addProduct($product);
     $another = Product::getNewInstance($root);
     $another->save();
     $this->assertTrue($list->contains($product));
     $this->assertFalse($list->contains($another));
 }
开发者ID:saiber,项目名称:livecart,代码行数:13,代码来源:ProductListTest.php

示例7: setUp

 public function setUp()
 {
     parent::setUp();
     $this->specField = SpecField::getNewInstance($this->rootCategory, SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_SELECTOR);
     $this->specField->save();
     $this->specFieldAutoIncrementNumber = $this->specField->getID();
     $specFieldValue = SpecFieldValue::getNewInstance($this->specField);
     $specFieldValue->save();
     $this->specFieldValueAutoIncrementNumber = $specFieldValue->getID();
     $this->product = Product::getNewInstance($this->rootCategory, 'test');
     $this->product->save();
     $this->productAutoIncrementNumber = $this->product->getID();
 }
开发者ID:saiber,项目名称:livecart,代码行数:13,代码来源:SpecFieldValueTest.php

示例8: setUp

 public function setUp()
 {
     parent::setUp();
     $this->product = Product::getNewInstance(Category::getRootNode(), 'test');
     $this->product->save();
     $this->option = ProductOption::getNewInstance($this->product);
     $this->option->type->set(ProductOption::TYPE_SELECT);
     $this->option->save();
     for ($k = 0; $k <= 1; $k++) {
         $choice = ProductOptionChoice::getNewInstance($this->option);
         $choice->priceDiff->set(10 + $k);
         $choice->save();
         $this->choices[] = $choice;
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:15,代码来源:ProductOptionTest.php

示例9: setUp

 public function setUp()
 {
     parent::setUp();
     Category::recalculateProductsCount();
     $this->root = Category::getNewInstance(Category::getRootNode());
     $this->root->save();
     for ($k = 1; $k <= 2; $k++) {
         $cat = Category::getNewInstance($this->root);
         $cat->save();
         $this->categories[$k] = $cat;
     }
     $this->product = Product::getNewInstance($this->categories[1]);
     $this->product->save();
     $this->secondCategory = ProductCategory::getNewInstance($this->product, $this->categories[2]);
     $this->secondCategory->save();
 }
开发者ID:saiber,项目名称:livecart,代码行数:16,代码来源:ProductCategoryTest.php

示例10: testProductRatingTypes

 public function testProductRatingTypes()
 {
     $subCategory = Category::getNewInstance(Category::getRootNode());
     $subCategory->save();
     $product = Product::getNewInstance($subCategory, 'test');
     $product->save();
     $rootType = ProductRatingType::getNewInstance(Category::getRootNode());
     $rootType->save();
     $subType = ProductRatingType::getNewInstance($subCategory);
     $subType->save();
     $types = ProductRatingType::getProductRatingTypes($product);
     $this->assertEqual($types->size(), 2);
     // parent category types should go first
     $this->assertSame($types->get(0), $rootType);
     $this->assertSame($types->get(1), $subType);
 }
开发者ID:saiber,项目名称:livecart,代码行数:16,代码来源:ProductRatingTypeTest.php

示例11: createOrder

 private function createOrder()
 {
     $user = User::getNewInstance('google@checkout.test');
     $user->save();
     $currency = Currency::getInstanceByID('USD');
     $product = Product::getNewInstance(Category::getRootNode());
     $product->isEnabled->set(true);
     $product->stockCount->set(100);
     $product->setPrice($currency, 100);
     $product->setValueByLang('name', null, 'Test name');
     $product->setValueByLang('shortDescription', null, 'Really short description');
     $product->save();
     $order = CustomerOrder::getNewInstance($user);
     $order->addProduct($product, 1);
     $order->save();
     return $order;
 }
开发者ID:saiber,项目名称:www,代码行数:17,代码来源:GoogleCheckoutTest.php

示例12: testGetProductGroups

 public function testGetProductGroups()
 {
     // new product
     $product = Product::getNewInstance($this->rootCategory, 'test');
     $product->save();
     $groups = array();
     foreach (range(1, 3) as $i) {
         $groups[$i] = ProductFileGroup::getNewInstance($product);
         $groups[$i]->position->set($i);
         $groups[$i]->setValueByLang('name', 'en', 'TEST_GROUP_' . $i);
         $groups[$i]->save();
     }
     $this->assertEqual(count($groups), ProductFileGroup::getProductGroups($product)->getTotalRecordCount());
     $i = 1;
     foreach (ProductFileGroup::getProductGroups($product) as $group) {
         $this->assertTrue($groups[$i] === $group);
         $i++;
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:19,代码来源:ProductFileGroupTest.php

示例13: testOrderTotalsWithRoundedPrices

 public function testOrderTotalsWithRoundedPrices()
 {
     $currency = Currency::getNewInstance('RON');
     $currency->setRoundingRule(0, Currency::TRIM, 0.09);
     $currency->save();
     $product = Product::getNewInstance(Category::getRootNode());
     $product->isEnabled->set(true);
     $product->setPrice($currency, 1.26);
     $product->save();
     $order = CustomerOrder::getNewInstance(SessionUser::getAnonymousUser());
     $order->addProduct($product);
     $order->save(true);
     $item = array_shift($order->getItemsByProduct($product));
     $this->assertEquals($product->getPrice($currency), 1.29);
     $this->assertEquals($item->getSubTotal(), 1.29);
     $item->count->set(2);
     $this->assertEquals($item->getSubTotal(), 2.58);
     $this->assertEquals($order->getTotal(true), 2.58);
     // add another currency to mix - no rounding rules
     $bgn = Currency::getNewInstance('BGN');
     $bgn->rate->set(2);
     $bgn->save();
     $item->count->set(2);
     $order->changeCurrency($bgn);
     $this->assertEquals($product->getPrice($bgn), 0.63);
     $this->assertEquals($item->getPrice(), 0.63);
     $this->assertSame($item->getCurrency(), $bgn);
     $this->assertEquals($item->getSubTotal(), 1.26);
     $this->assertEquals($order->getTotal(true), 1.26);
     // add rounding rules
     $bgn->clearRoundingRules();
     $bgn->setRoundingRule(0, Currency::TRIM, 0.07000000000000001);
     $order->changeCurrency($bgn);
     $this->assertEquals($product->getPrice($bgn), 0.67);
     $this->assertEquals($item->getSubTotal(), 1.34);
     $this->assertEquals($order->getTotal(true), 1.34);
 }
开发者ID:saiber,项目名称:livecart,代码行数:37,代码来源:CurrencyTest.php

示例14: 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) {
//.........这里部分代码省略.........
开发者ID:GregerA,项目名称:livecart,代码行数:101,代码来源:ProductImport.php

示例15: testClone

 public function testClone()
 {
     $image = ActiveRecordModel::getNewInstance('ProductImage');
     $image->product->set($this->product);
     $image->save();
     $this->assertSame($image, $this->product->defaultImage->get());
     $numField = SpecField::getNewInstance($this->productCategory, SpecField::DATATYPE_NUMBERS, SpecField::TYPE_NUMBERS_SIMPLE);
     $numField->save();
     $this->product->setAttributeValue($numField, 100);
     $this->product->save();
     $option = ProductOption::getNewInstance($this->product);
     $option->type->set(ProductOption::TYPE_SELECT);
     $option->setValueByLang('name', 'en', 'test');
     $option->save();
     $related = Product::getNewInstance($this->productCategory, 'related');
     $related->save();
     $relGroup = ProductRelationshipGroup::getNewInstance($this->product, ProductRelationship::TYPE_CROSS);
     $relGroup->save();
     $rel = ProductRelationship::getNewInstance($this->product, $related, $relGroup);
     $rel->save();
     $this->assertEquals(1, $this->product->getRelationships()->size());
     $cloned = clone $this->product;
     $this->assertEquals(100, $cloned->getSpecification()->getAttribute($numField)->value->get());
     $cloned->setAttributeValue($numField, 200);
     $cloned->setPrice($this->usd, 80);
     $cloned->save();
     $this->assertNotEquals($cloned->getID(), $this->product->getID());
     ActiveRecordModel::clearPool();
     $reloaded = Product::getInstanceByID($cloned->getID(), true);
     $reloaded->loadPricing();
     $this->assertEquals(80, $reloaded->getPrice($this->usd));
     $reloaded->loadSpecification();
     $this->assertEquals(200, $reloaded->getSpecification()->getAttribute($numField)->value->get());
     // related products
     $rel = $reloaded->getRelationships();
     $this->assertEquals(1, $rel->size());
     $this->assertSame($reloaded, $rel->get(0)->productRelationshipGroup->get()->product->get());
     // options
     $clonedOpts = ProductOption::getProductOptions($reloaded);
     $this->assertEquals(1, $clonedOpts->size());
     // image
     $this->assertTrue(is_object($reloaded->defaultImage->get()));
     $this->assertNotEquals($reloaded->defaultImage->get()->getID(), $this->product->defaultImage->get()->getID());
 }
开发者ID:saiber,项目名称:livecart,代码行数:44,代码来源:ProductTest.php


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