function valuesToForm(&$ret, Product $record) { if ($record->isLoaded()) { $ret['_categories'] = $record->getCategories(); $ret['_plan'] = array(); foreach ($record->getBillingPlans() as $plan) { $arr = $plan->toArray(); $arr['paysys_id'] = $arr['paysys_id'] ? explode(',', $arr['paysys_id']) : array(); if (!empty($arr['rebill_times'])) { $arr['_rebill_times'] = $arr['rebill_times']; if (!in_array($arr['rebill_times'], array(0, 1, IProduct::RECURRING_REBILLS))) { $arr['_rebill_times'] = 'x'; } } foreach (array('first_period', 'second_period') as $f) { if (array_key_exists($f, $arr)) { $arr[$f] = new Am_Period($arr[$f]); } } $ret['_plan'][$plan->pk()] = $arr; } } }
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; }