예제 #1
0
 /**
  * Insert a new Product  returns the ID of the newly created record
  * @param Product $product
  * @return mixed
  * @throws ShopException
  */
 public function insertProduct(Product $product)
 {
     $product->product_srl = getNextSequence();
     if ($product->discount_price >= $product->price) {
         throw new ShopException("Discount price is bigger than normal price");
     }
     $output = executeQuery('shop.insertProduct', $product);
     if (!$output->toBool()) {
         throw new ShopException($output->getMessage(), $output->getError());
     } else {
         $this->insertProductCategories($product);
         $this->insertProductAttributes($product);
         if ($product->product_type == 'configurable') {
             $this->insertProductConfigurableAttributes($product);
         }
         $this->insertProductImages($product);
     }
     $slug = ShopUtils::slugify($product->title);
     return $product->product_srl;
 }
 /**
  * Returns an absolute url for category with friendly_url $slug
  *
  * @author Florin Ercus (dev@xpressengine.org)
  *
  * @param      $slug string
  *
  * @param bool $relative
  * @return string absolute url
  */
 public static function getUrl($slug, $relative = TRUE)
 {
     return ShopUtils::getUrl("category/{$slug}", $relative);
 }
예제 #3
0
		public function procShopToolInsertDuplicate(){
			$shopModel = $this->model;
			$productRepository = $shopModel->getProductRepository();

			$product_srl = Context::get('product_srl');
			$product = $productRepository->getProduct($product_srl);
			$product->title = 'Copy of '.$product->title;
			$product->sku = 'Copy-'.$product->sku;
            $product->friendly_url = ($product->friendly_url ? $product->friendly_url : ShopUtils::slugify($product->title)) . "_copy";
			foreach($product->images as $image){
				unset($image->image_srl);
				$path = sprintf('./files/attach/images/shop/%d/product-images/%d/', $image->module_srl , $image->product_srl);
				$image->source_filename = sprintf('%s%s', $path, $image->filename);
			}
			unset($product_srl);
			$productRepository->insertProduct($product);
            $productRepository->updatePrimaryImageFilename($product);
            $this->setMessage("A product has been successfully duplicated");
			$returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolManageProducts');
			$this->setRedirectUrl($returnUrl);
		}