public function testLoadSpecification() { ActiveRecord::removeFromPool($this->product); $this->product = Product::getInstanceByID($this->product->getID(), true); $this->product->loadSpecification(); // save as soon as the specification is loaded to make sure all associated objects are marked as existing. // and won't be re-inserted in database try { $this->product->save(); $this->pass(); } catch (Exception $e) { $this->fail(); } // set prices foreach ($this->product->getApplication()->getCurrencyArray() as $currency) { $this->product->setPrice($currency, 111); } $this->product->save(); $arr = $this->product->toArray(); foreach ($this->product->getApplication()->getCurrencyArray() as $currency) { $this->assertEqual($arr['price_' . $currency], 111); } // re-run all the previous tests on the restored object $this->testSimpleValues(); $this->testSingleSelectValues(); $this->testMultipleSelectValues(); $arr = $this->product->toArray(); }
public function testCalculatePrices() { // Create new prices $this->product->setPrice(self::getApplication()->getDefaultCurrencyCode(), $defaultPrice = 1); $this->product->save(); // Just check that prices for other currencies are generated $this->product->loadSpecification(); $pricing = $this->product->getPricingHandler(); $prices = $pricing->toArray(ProductPricing::BOTH); foreach (self::getApplication()->getCurrencyArray(!LiveCart::INCLUDE_DEFAULT) as $currencyCode) { $this->assertTrue(isset($prices[ProductPricing::CALCULATED][$currencyCode]) && $prices[ProductPricing::CALCULATED][$currencyCode] > 0); $this->assertFalse(isset($prices[ProductPricing::DEFINED][$currencyCode])); } }
private function productForm(Product $product) { $productFormData = $product->toArray(); if ($product->isLoaded()) { $product->loadSpecification(); $productFormData = array_merge($productFormData, $product->getSpecification()->getFormData()); if (isset($productFormData['Manufacturer']['name'])) { $productFormData['manufacturer'] = $productFormData['Manufacturer']['name']; } } else { $product->load(ActiveRecord::LOAD_REFERENCES); } $product->loadPricing(); $form = $this->buildForm($product); $pricing = $product->getPricingHandler(); $pricesData = $product->toArray(); $listPrices = $pricing->toArray(ProductPricing::DEFINED, ProductPricing::LIST_PRICE); $pricesData['shippingHiUnit'] = (int) $pricesData['shippingWeight']; $pricesData['shippingLoUnit'] = ($pricesData['shippingWeight'] - $pricesData['shippingHiUnit']) * 1000; if (array_key_exists('defined', $pricesData)) { foreach ($pricesData['calculated'] as $currency => $price) { $pricesData['price_' . $currency] = isset($pricesData['defined'][$currency]) ? $pricesData['defined'][$currency] : ''; $productFormData['price_' . $currency] = $pricesData['price_' . $currency]; } } foreach ($listPrices as $currency => $price) { $pricesData['listPrice_' . $currency] = $price; } $form->setData($productFormData); // status values $status = array(0 => $this->translate('_disabled'), 1 => $this->translate('_enabled')); // product types $types = array(Product::TYPE_TANGIBLE => $this->translate('_tangible'), Product::TYPE_DOWNLOADABLE => $this->translate('_intangible'), Product::TYPE_BUNDLE => $this->translate('_bundle')); // default product type if (!$product->isLoaded()) { $product->type->set(substr($this->config->get('DEFAULT_PRODUCT_TYPE'), -1)); $form->set('type', $product->type->get()); } $response = new ActionResponse(); $product->getSpecification()->setFormResponse($response, $form); $response->set("cat", $product->getCategory()->getID()); $response->set("hideFeedbackMessage", $this->request->get("afterAdding") == 'on'); $response->set("productForm", $form); $response->set("path", $product->getCategory()->getPathNodeArray(true)); $response->set("productTypes", $types); $response->set("productStatuses", $status); $response->set("baseCurrency", $this->application->getDefaultCurrency()->getID()); $response->set("otherCurrencies", $this->application->getCurrencyArray(LiveCart::EXCLUDE_DEFAULT_CURRENCY)); $response->set("shippingClasses", $this->getSelectOptionsFromSet(ShippingClass::getAllClasses())); $response->set("taxClasses", $this->getSelectOptionsFromSet(TaxClass::getAllClasses())); $productData = $product->toArray(); if (empty($productData['ID'])) { $productData['ID'] = 0; } $response->set("product", $productData); return $response; }