Ejemplo n.º 1
0
        /**
         * insert product function
         * @return Object
         */
        public function procShopToolInsertProduct()
        {
            $shopModel = $this->model;
            $productRepository = $shopModel->getProductRepository();
			$imageRepository = $shopModel->getImageRepository();

            $args = Context::getRequestVars();
			if(is_array($args->filesToUpload)) $args->images = $imageRepository->createImagesUploadedFiles($args->filesToUpload);
			if(!isset($args->primary_image) && isset($args->images)) $args->images[0]->is_primary = 'Y';
			if(isset($args->primary_image) && isset($args->images[$args->primary_image]))	{
				$args->images[$args->primary_image]->is_primary = 'Y';
				unset($args->primary_image);
			}

            $logged_info = Context::get('logged_info');
            $args->member_srl = $logged_info->member_srl;
            $args->module_srl = $this->module_info->module_srl;

			if($args->product_type == 'simple')
			{
				$product = new SimpleProduct($args);
			}
			else
			{
				$product = new ConfigurableProduct($args);
			}

            try
            {
                if (!$product->isPersisted())
                {
                    $productRepository->insertProduct($product);

					if ($product->isSimple())
					{
						$this->setMessage("Saved simple product successful");
						$returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolManageProducts');
					}
					else
					{
						$this->setMessage("Saved configurable product successful");
						$returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolAddAssociatedProducts','product_srl',$product->product_srl);
					}
                }
                else
                {
					$product->delete_images = $args->delete;

                    $productRepository->updateProduct($product);

                    if ($product->isSimple())
					{
						$this->setMessage("Updated simple product successfull");
					}
					else
					{
						$this->setMessage("Updated configurable product successfull");
					}

					if ($product->isSimple() && $product->parent_product_srl)
					{
						$returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolEditProduct', 'product_srl', $product->parent_product_srl);
					}
					else
					{
						$returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolManageProducts');
					}
                }
				$productRepository->updatePrimaryImageFilename($product);
            }
            catch(Exception $e)
            {
                return new Object(-1, $e->getMessage());
            }

			$this->setRedirectUrl($returnUrl);
        }