/** * @return DescriptionCollection */ public function getDescriptions() { if (is_null($this->descriptions)) { $this->descriptions = OptionDAO::getInstance()->getOptionValueDescriptions($this->id); } return $this->descriptions; }
protected function initModel() { if ($this->getRequest()->getMethod() == 'POST') { // Cases: submit create and update data $descriptions = new DescriptionCollection(); foreach ($this->getRequest()->getParam('product_description') as $language => $description) { $descriptions->addDescription(new Description($language, $description['name'], $description['description'], $description['meta_description'], $description['meta_keyword'], $description['seo_title'], $description['seo_h1'])); } $categories = []; foreach ($this->getRequest()->getParam('product_category') as $categoryId) { $categories[] = new ProductCategory(new Category($categoryId), $categoryId == $this->getRequest()->getParam('main_category_id')); } $this->model = new Product(0, $this->getLanguage()->getId(), null, $this->getRequest()->getParam('affiliate_commission'), null, $this->getRequest()->getParam('date_available'), null, $descriptions, new Dimensions($this->getRequest()->getParam('length_class_id'), $this->getRequest()->getParam('height'), $this->getRequest()->getParam('length'), $this->getRequest()->getParam('width')), $this->getRequest()->getParam('image'), $this->getRequest()->getParam('keyword'), $this->getRequest()->getParam('koreanName'), $this->getRequest()->getParam('location'), $this->getRequest()->getParam('manufacturer_id'), $this->getRequest()->getParam('minimum'), $this->getRequest()->getParam('model'), null, $this->getRequest()->getParam('points'), $this->getRequest()->getParam('price'), $this->getRequest()->getParam('quantity'), $this->getRequest()->getParam('shipping'), $this->getRequest()->getParam('sku'), $this->getRequest()->getParam('sort_order'), $this->getRequest()->getParam('status'), $this->getRequest()->getParam('stock_status_id'), $this->getRequest()->getParam('product_store'), $this->getRequest()->getParam('subtract'), new Supplier($this->getRequest()->getParam('supplier_id')), $this->getRequest()->getParam('supplierUrl'), $this->getRequest()->getParam('product_tag'), $this->getRequest()->getParam('upc'), null, null, new Weight($this->getRequest()->getParam('weight_class_id'), $this->getRequest()->getParam('weight')), $this->getRequest()->getParam('product_attribute'), $this->getRequest()->getParam('product_discount'), $this->getRequest()->getParam('product_special'), $this->getRequest()->getParam('product_download'), $categories, $this->getRequest()->getParam('product_related'), $this->getRequest()->getParam('product_layout'), $this->getRequest()->getParam('product_reward'), $this->getRequest()->getParam('image_description')); $productOptions = new ProductOptionCollection(); foreach ($this->getRequest()->getParam('product_option') as $productOptionParam) { $productOption = new ProductOption($productOptionParam['product_option_id'], $this->model, OptionDAO::getInstance()->getOptionById($productOptionParam['option_id']), null, $productOptionParam['required'], 0, false); if ($productOption->getOption()->isSingleValueType()) { $productOption->setValue($productOptionParam['option_value']); } else { if ($productOption->getOption()->isMultiValueType()) { foreach ($productOptionParam['product_option_value'] as $productOptionValueParam) { $productOption->getValue()->attach(new ProductOptionValue($productOptionValueParam['product_option_value_id'], $productOption, new OptionValue($productOption->getOption(), $productOptionValueParam['option_value_id']), $productOptionValueParam['quantity'], $productOptionValueParam['subtract'], $productOptionValueParam['price_prefix'] == '+' ? $productOptionValueParam['price'] : -$productOptionValueParam['price'], $productOptionValueParam['points_prefix'] == '+' ? $productOptionValueParam['points'] : -$productOptionValueParam['points'], $productOptionValueParam['weight_prefix'] == '+' ? $productOptionValueParam['weight'] : -$productOptionValueParam['weight'], 0)); } } } $productOptions->attach($productOption); } $auctions = []; foreach ($this->getRequest()->getParam('product_auctions') as $productAuctionParam) { $auctions[] = new Auction(null, $this->model, $this->getRequest()->getParam('auction_name', $this->getConfig()->get('auction_name')), $this->getRequest()->getParam('isauction', $this->getConfig()->get('isauction')), $this->getRequest()->getParam('auction_min', $this->getConfig()->get('auction_min')), $this->getRequest()->getParam('auction_max', $this->getConfig()->get('auction_max')), $this->getRequest()->getParam('auction_start', $this->getConfig()->get('auction_start')), $this->getRequest()->getParam('auction_end', $this->getConfig()->get('auction_end'))); } $this->model->setImages($this->getRequest()->getParam('product_image')); $this->model->setOptions($productOptions); $this->model->setAuctions($auctions); if ($this->getRequest()->getParam('product_id')) { // Case: submit update changes $this->model->setId($this->getRequest()->getParam('product_id')); } //TODO: Something to do with UrlAlias } else { if ($this->getRequest()->getParam('product_id')) { // Case: update fill the form for editing $this->model = ProductDAO::getInstance()->getProduct($this->getRequest()->getParam('product_id'), false, true); } else { // Case: create open the form for editing $this->model = new Product(0, $this->getLanguage()->getId()); } } }
public function setOption() { if ($this->getCache()->get('isSetOptionRunning')) { $this->getLogger()->write("Tried to run setOption() again"); return; } $initialTime = ini_get('max_execution_time'); ini_set('max_execution_time', 3600); session_write_close(); $this->getCache()->set('isSetOptionRunning', true); $option = OptionDAO::getInstance()->getOptionById($this->parameters['optionId']); $this->loadFilter(); $count = 0; foreach ($this->mpfilter["products"] as $product) { $this->getCache()->set('progress', "Step 2 of 2. Setting options for product " . $count++ . " of " . sizeof($this->mpfilter["products"])); if (in_array($product['product_id'], $this->mpfilter['change_ids']) || $this->mpfilter['change_all']) { $product = ProductDAO::getInstance()->getProduct($product['product_id'], true); $productOptions = $product->getOptions(); if ($this->parameters['operation'] == 'AddOption') { if (is_null($productOptions->getByOptionId($option->getId()))) { $productOptions->attach(new ProductOption(null, $product, $option, null, false, null)); } } elseif ($this->parameters['operation'] == 'DelOption') { $productOptions->detach($productOptions->getByOptionId($option->getId())); } elseif ($this->parameters['operation'] == 'AddValue') { $productOption = $productOptions->getByOptionId($option->getId()); if (is_null($productOption)) { $productOption = new ProductOption(null, $product, $option, null, false, null); $productOptions->attach($productOption); } if ($productOption->getOption()->isSingleValueType()) { $productOption->setValue($this->parameters['optionValue']); } else { // Option value type is multivalue if (is_null($productOption->getValue()->getByOptionValueId($this->parameters['optionValue']))) { $productOption->setValue(new ProductOptionValue(null, $productOption, new OptionValue($option, $this->parameters['optionValue']), 0, 0, $this->parameters['price'], 0, $this->parameters['weight'], null)); } } } elseif ($this->parameters['operation'] == 'DelValue') { $productOption = $productOptions->getByOptionId($option->getId()); if (!is_null($productOption)) { if ($productOption->getOption()->isSingleValueType()) { $productOption->deleteValue(); } elseif ($productOption->getOption()->isMultiValueType()) { $productOption->deleteValue(new ProductOptionValue(null, $productOption, new OptionValue($option, $this->parameters['optionValue']), null, null, null, null, null, null)); } else { throw new InvalidArgumentException("Not acceptable option value type '" . $this->parameters['optionValueType'] . "'"); } } } ProductDAO::getInstance()->saveProduct($product); } } ini_set('max_execution_time', $initialTime); $this->getCache()->delete('isSetOptionRunning'); }
/** * @param ProductOption $productOption * @return ProductOptionValueCollection|string */ public function getProductOptionValues($productOption) { if ($productOption->getOption()->isSingleValueType()) { return $this->getDb()->queryScalar("SELECT option_value FROM product_option WHERE product_option_id = :productOptionId", [':productOptionId' => $productOption->getId()]); } elseif ($productOption->getOption()->isMultiValueType()) { $product_option_value_query = $this->getDb()->query("\n SELECT *\n FROM\n product_option_value AS pov\n LEFT JOIN option_value AS ov ON pov.option_value_id = ov.option_value_id\n LEFT JOIN option_value_description AS ovd ON ov.option_value_id = ovd.option_value_id\n WHERE\n pov.product_id = :productId\n AND pov.product_option_id = :productOptionId\n AND ovd.language_id = :languageId\n ORDER BY ov.sort_order\n ", [':productId' => $productOption->getProduct()->getId(), ':productOptionId' => $productOption->getId(), ':languageId' => $this->getConfig()->get('config_language_id')]); $productOptionValues = new ProductOptionValueCollection(); foreach ($product_option_value_query->rows as $productOptionValueRow) { $productOptionValues->attach(new ProductOptionValue($productOptionValueRow['product_option_value_id'], $productOption, OptionDAO::getInstance()->getOptionValues($productOption->getOption()->getId())->getById($productOptionValueRow['option_value_id']), $productOptionValueRow['quantity'], $productOptionValueRow['subtract'], $productOptionValueRow['price_prefix'] == '+' ? $productOptionValueRow['price'] : -$productOptionValueRow['price'], $productOptionValueRow['points_prefix'] == '+' ? $productOptionValueRow['points'] : -$productOptionValueRow['points'], $productOptionValueRow['weight_prefix'] == '+' ? $productOptionValueRow['weight'] : -$productOptionValueRow['weight'], $productOptionValueRow['afc_id'])); } return $productOptionValues; } else { throw new \InvalidArgumentException("Unknown option value type '" . $productOption->getOption()->getType() . "'"); } }
/** * @return OptionValueCollection */ public function getValues() { if (!isset($this->values)) { $this->values = OptionDAO::getInstance()->getOptionValues($this->id); } return $this->values; }