Example #1
0
 public function testObject()
 {
     $product = new Product();
     $product->setTitle('title');
     $product->setSize('10k');
     $product->setUnitPrice('10');
     $product->setDescription('description');
     $products = new Products();
     $products->add($product);
     $this->assertArrayHasKey('total', $products->getItems());
 }
Example #2
0
 private function createProducts()
 {
     $ipad = new Product();
     $ipad->setId(1);
     $ipad->setDescription('A brand new 16 GIGA iPad');
     $ipad->setPrice('499.00');
     $this->allProducts[] = $ipad;
     $iphone = new Product();
     $iphone->setId(2);
     $iphone->setDescription('A brand new 32 GIGA iPhone');
     $iphone->setPrice(599.0);
     $this->allProducts[] = $iphone;
     $ipod = new Product();
     $ipod->setId(3);
     $ipod->setDescription('A brand new 8 GIGA iPod');
     $ipod->setPrice(299.0);
     $this->allProducts[] = $ipod;
 }
Example #3
0
function createProduct()
{
    //Product 1
    $product1 = new Product();
    $product1->setCode(1);
    $product1->setDescription("Produto de teste 1");
    $product1->setAmount(2);
    $product1->setValue(5.5);
    $product1->setExtraDescription("Este produto é um exemplo");
    //Product 2
    $product2 = new Product();
    $product2->setCode(2);
    $product2->setDescription("Produto de teste 2");
    $product2->setAmount(1);
    $product2->setValue(9);
    $product2->setExtraDescription("");
    //Product Array
    $products = array($product1, $product2);
    return $products;
}
 public function create(SubCategory $sub_category, $name, $description, $price, $img, $stock)
 {
     $errors = array();
     $product = new Product($this->db);
     try {
         $product->setSubCategory($sub_category);
         $product->setName($name);
         $product->setDescription($description);
         $product->setPrice($price);
         $product->setImg($img);
         $product->setStock($stock);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     $errors = array_filter($errors, function ($val) {
         return $val !== true;
     });
     if (count($errors) == 0) {
         $idSubCategory = intval($product->getIdSubCategory());
         $name = $this->db->quote($product->getName());
         $description = $this->db->quote($product->getDescription());
         $price = $this->db->quote($product->getPrice());
         $img = $this->db->quote($product->getImg());
         $stock = $this->db->quote($product->getStock());
         $query = "INSERT INTO product(id_sub_category, name, description, price, img, stock) VALUES('" . $idSub_category . "', " . $name . ", " . $description . ", " . $price . ", " . $img . ", " . $stock . ")";
         $res = $this->db->exec($query);
         if ($res) {
             $id = $this->db->lastInsertId();
             if ($id) {
                 return $this->findById($id);
             } else {
                 return "Internal Server error";
             }
         }
     } else {
         return $errors;
     }
 }
Example #5
0
 public function getProducts()
 {
     $db = Database::getDB();
     $query = 'SELECT * FROM products
               INNER JOIN categories
                   ON products.categoryID = categories.categoryID';
     $result = $db->query($query);
     $products = array();
     foreach ($result as $row) {
         // create the Category object
         $category = new Category();
         $category->setID($row['categoryID']);
         $category->setName($row['categoryName']);
         // create the Product object
         $product = new Product();
         $product->setCategory($category);
         $product->setId($row['productID']);
         $product->setName($row['productName']);
         $product->setDescription($row['productDescription']);
         $product->setPrice($row['listPrice']);
         $products[] = $product;
     }
     return $products;
 }
Example #6
0
 /**
  * @param $itemsPerPage
  * @param $pageNumber
  * @return Product[]
  */
 public function getProducts($itemsPerPage = -1, $pageNumber = -1)
 {
     APIWrapper::verifyReadiness();
     $products = array();
     $requestURL = "https://app.fetchapp.com/api/v2/products.xml?";
     if ($itemsPerPage != -1) {
         $requestURL .= "per_page=" . $itemsPerPage;
     }
     if ($pageNumber != -1) {
         $requestURL .= $itemsPerPage != -1 ? "&" : "";
         $requestURL .= "page=" . $pageNumber;
     }
     $requestURL = rtrim($requestURL, '?');
     $results = APIWrapper::makeRequest($requestURL, "GET");
     if (is_a($results, "SimpleXMLElement")) {
         foreach ($results->product as $product) {
             $tempProduct = new Product();
             $tempProduct->setProductID($product->id);
             $tempProduct->setSKU($product->sku);
             $tempProduct->setName($product->name);
             $tempProduct->setDescription($product->description);
             $tempProduct->setPrice($product->price);
             $tempProduct->setCurrency(Currency::getValue($product->currency));
             $tempProduct->setOrderCount($product->order_count);
             $tempProduct->setDownloadCount($product->download_count);
             $tempProduct->setPaypalAddToCartLink($product->paypal_add_to_cart_link['href']);
             $tempProduct->setPaypalBuyNowLink($product->paypal_buy_now_link['href']);
             $tempProduct->setPaypalViewCartLink($product->paypal_view_cart_link['href']);
             $tempProduct->setCreationDate(new \DateTime($product->created_at));
             $tempProduct->setFilesUri($product->files_uri);
             $tempProduct->setDownloadsUri($product->downloads_uri);
             $products[] = $tempProduct;
         }
     }
     return $products;
 }
Example #7
0
 /**
  * The handler of creating product.
  * @param  String  $productName         - the name of product in JSON format
  * @param  String  $productCategorySlug - the unique slug of the product category
  * @param  User    $developer           - the user object of the developer of the product
  * @param  String  $productLogoUrl      - the URL of the logo of the product
  * @param  String  $latestVersion       - the latest version of the product
  * @param  String  $productUrl          - the homepage of the product
  * @param  String  $prerequisites       - the prerequisites of testing in JSON format
  * @param  String  $description         - the description of the product in JSON format
  * @param  boolean $isTokenValid        - whether the CSRF token is valid
  * @return an array infers whether the creation is successful
  */
 public function createProduct($productName, $productCategorySlug, $developer, $productLogoUrl, $latestVersion, $productUrl, $prerequisites, $description, $isTokenValid)
 {
     $productCategory = $this->getProductCategoryUsingSlug($productCategorySlug);
     $result = array('isSuccessful' => false, 'isProductNameEmpty' => $this->isProductNameEmpty($productName), 'isProductNameLegal' => $this->isProductNameLegal($productName), 'isProductCategoryLegal' => $productCategory != NULL, 'isDeveloperLegal' => $developer != NULL, 'isProductLogoEmpty' => empty($productLogoUrl), 'isProductLogoLegal' => $this->isProductLogoLegal($productLogoUrl), 'isLatestVersionEmpty' => empty($latestVersion), 'isLatestVersionLegal' => $this->isLatestVersionLegal($latestVersion), 'isProductUrlEmpty' => empty($productUrl), 'isProductUrlLegal' => $this->isProductUrlLegal($productUrl), 'isPrerequisitesEmpty' => $this->isPrerequisitesEmpty($prerequisites), 'isPrerequisitesLegal' => $this->isPrerequisitesLegal($prerequisites), 'isDescriptionEmpty' => $this->isDescriptionEmpty($description), 'isDescriptionLegal' => $this->isDescriptionLegal($description), 'isTokenValid' => $isTokenValid);
     $result['isSuccessful'] = !$result['isProductNameEmpty'] && $result['isProductNameLegal'] && $result['isProductCategoryLegal'] && $result['isDeveloperLegal'] && !$result['isProductLogoEmpty'] && $result['isProductLogoLegal'] && !$result['isLatestVersionEmpty'] && $result['isLatestVersionLegal'] && !$result['isProductUrlEmpty'] && $result['isProductUrlLegal'] && !$result['isPrerequisitesEmpty'] && $result['isPrerequisitesLegal'] && !$result['isDescriptionEmpty'] && $result['isDescriptionLegal'] && $result['isTokenValid'];
     if ($result['isSuccessful']) {
         $product = new Product();
         $product->setProductName($productName);
         $product->setProductCategory($productCategory);
         $product->setDeveloper($developer);
         $product->setProductLogo($productLogoUrl);
         $product->setLatestVersion($latestVersion);
         $product->setProductUrl($productUrl);
         $product->setPrerequisites($prerequisites);
         $product->setDescription($description);
         if (!$product->create()) {
             $result['isSuccessful'] = false;
         }
     }
     return $result;
 }
Example #8
0
<?php

require_once 'Product.php';
require_once 'Tool.php';
require_once 'Electronic.php';
$form = new Product();
if (isset($_POST['submit'])) {
    $form->setTitle($_POST['title']);
    $form->setDescription($_POST['description']);
    $form->setPrice($_POST['price']);
    $form->saveProduct();
}
Example #9
0
 public function importProducts(Import $entity, $output)
 {
     $sql = ' SELECT p.*, o.nombre as opticName, m.nombre as brand, mo.nombre as model, s.nombre as category FROM  `producto` AS p ' . ' LEFT JOIN optica AS o ON o.id = p.id_optica ' . ' LEFT JOIN servicio AS s ON s.id = p.id_servicio ' . ' LEFT JOIN marca AS m ON m.id_marca = p.id_marca ' . ' LEFT JOIN modelo AS mo ON mo.id_modelo = p.id_modelo ' . ' ORDER BY p.id ' . ' LIMIT ' . $entity->getLimitStart() . ', ' . $entity->getLimitEnd();
     $link = mysqli_connect($entity->getServer(), $entity->getUsername(), $entity->getPassword(), $entity->getDbname()) or die('No se pudo conectar: ' . mysqli_error($link));
     $resultado = $link->query($sql);
     $x = 0;
     if (mysqli_num_rows($resultado) > 0) {
         while ($fila = mysqli_fetch_assoc($resultado)) {
             $x++;
             print_r($x . '-' . utf8_encode($fila['nombre']));
             echo PHP_EOL;
             $em = $this->container->get('doctrine')->getManager();
             $optic = $em->getRepository('CoreBundle:Optic')->findOneByName(utf8_encode($fila['opticName']));
             $category = $em->getRepository('EcommerceBundle:Category')->findOneByName(utf8_encode($fila['category']));
             $brand = $em->getRepository('EcommerceBundle:Brand')->findOneByName(utf8_encode($fila['brand']));
             $model = $em->getRepository('EcommerceBundle:BrandModel')->findOneByName(utf8_encode($fila['model']));
             //Create Products
             if ($optic instanceof Optic && $fila['id'] != 746 && $fila['id'] != 747 && $fila['id'] != 748 && $fila['id'] != 749 && $fila['id'] != 750 && $fila['id'] != 751 && $fila['id'] != 752 && $fila['id'] != 753) {
                 $product = new Product();
                 $product->setName(utf8_encode($fila['nombre']));
                 $product->setDescription(utf8_encode($fila['descripcion']));
                 if ($fila['precio_original'] != '') {
                     $product->setInitPrice($fila['precio_original']);
                 } else {
                     $product->setInitPrice(0);
                 }
                 $product->setPrice($fila['precio']);
                 if ($fila['tipo_precio'] != '') {
                     $product->setPriceType($fila['tipo_precio']);
                 } else {
                     $product->setPriceType(0);
                 }
                 $product->setDiscount($fila['descuento']);
                 $product->setDiscountType($fila['tipo_descuento']);
                 if ($fila['stock'] != '') {
                     $product->setStock($fila['stock']);
                 } else {
                     $product->setStock(0);
                 }
                 $product->setWeight($fila['kilos']);
                 $product->setOutlet($fila['outlet']);
                 $product->setPublic($fila['publicado']);
                 if ($fila['recoger_tienda'] != '') {
                     $product->setStorePickup($fila['recoger_tienda']);
                 } else {
                     $product->setStorePickup(0);
                 }
                 $product->setMetaTitle(utf8_encode($fila['meta_titulo']));
                 $product->setMetaDescription(utf8_encode($fila['meta_descripcion']));
                 $product->setMetaTags(utf8_encode($fila['meta_keywords']));
                 $product->setOptic($optic);
                 $product->setBrand($brand);
                 $product->setModel($model);
                 $product->setCategory($category);
                 $product->setActive(true);
                 $product->setAvailable(true);
                 $product->setHighlighted(false);
                 $product->setFreeTransport(false);
                 $slug = $this->slugify(utf8_encode($fila['nombre'] . '-' . $optic->getCity()));
                 //                    $p = $em->getRepository('EcommerceBundle:Product')->findOneBySlug($slug);
                 //                    if($p instanceof Product) $slug = $slug.'_'.rand(1000,9999);
                 $product->setSlug($slug);
                 $em->persist($product);
                 $em->flush();
                 //image
                 if ($fila['imagen'] != '') {
                     $imagePath = '';
                     $dir = '/home/sebastian/www/src/Symfony/web/uploads/documents';
                     $absoluteImagePath = $dir . '/' . utf8_encode($fila['imagen']);
                     if (file_exists($absoluteImagePath . '.jpeg')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.jpeg';
                     }
                     if (file_exists($absoluteImagePath . '.jpg')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.jpg';
                     }
                     if (file_exists($absoluteImagePath . '.gif')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.gif';
                     }
                     if (file_exists($absoluteImagePath . '.png')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.png';
                     }
                     //Thumb
                     $imagePathThumb = '';
                     $absoluteImagePathThumb = $dir . '/' . utf8_encode($fila['imagen']) . '_260.jpg';
                     if (file_exists($absoluteImagePathThumb)) {
                         $imagePathThumb = utf8_encode($fila['imagen']) . '_260.jpg';
                     }
                     $imagePathThumb2 = '';
                     $absoluteImagePathThumb2 = $dir . '/' . utf8_encode($fila['imagen']) . '_142.jpg';
                     if (file_exists($absoluteImagePathThumb2)) {
                         $imagePathThumb2 = utf8_encode($fila['imagen']) . '_142.jpg';
                     }
                     if ($imagePath == '') {
                         $dir = 'http://web.com/uploads/documents/';
                         $imagePath = $fila['imagen'] . '.' . $fila['extension_img'];
                     }
                     print_r($dir . '/' . $imagePath);
                     echo PHP_EOL;
                     @mkdir(__DIR__ . '/../../../../../web/uploads/images/product');
                     @mkdir(__DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId());
                     @mkdir(__DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail');
                     copy($dir . '/' . $imagePath, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/' . $imagePath);
                     if ($imagePathThumb != '') {
                         copy($dir . '/' . $imagePathThumb, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail/' . $imagePathThumb);
                     }
                     if ($imagePathThumb2 != '') {
                         copy($dir . '/' . $imagePathThumb2, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail/' . $imagePathThumb2);
                     }
                     $image0 = new Image();
                     $image0->setPath($imagePath);
                     $product->addImage($image0);
                     $em->persist($image0);
                 }
                 $em->flush();
             }
         }
     }
 }
Example #10
0
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\ClassLoader\ClassMapGenerator;
ClassMapGenerator::dump(array(__DIR__ . '/src'), __DIR__ . '/class_map.php');
use Symfony\Component\ClassLoader\MapClassLoader;
$mapping = (include __DIR__ . '/class_map.php');
$loader = new MapClassLoader($mapping);
$loader->register();
use Goutte\Client;
use Guzzle\Common\Event;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
date_default_timezone_set('Europe/London');
$client = new Client();
$url_crawl = 'http://www.sainsburys.co.uk/webapp/wcs/stores/servlet/CategoryDisplay?msg=&categoryId=185749&langId=44&storeId=10151&krypto=CWSPwJn7%2FfNCQJ17kIzWIEvEWIHZR3Bj3iR4i5MAF9M7qzk%2FP9%2B4zVL66KSWG186Uk9LnjKfPgCi%0AMsUYGCAI6oj6XhceppObUmu5R1ud8Z7wJuqB5X214E%2BBA47VydOEDYPnnJM%2BvN%2FIT5QMVV5%2B2aGv%0Alb1unCWjvafVBq7m6USN2aiCjWKM5mUPqPuXdvOWsUIFwpRb3OMbqw0sp5n8RyO6gCstruK1H%2B3L%0AGstBthGCZEJIXfuWPan04OtMjtzKYB1lUYa1f1JJu7YBoqhhyEgYYl0MlcS8vhp8Dn4dsKY%3D#langId=44&storeId=10151&catalogId=10137&categoryId=185749&parent_category_rn=12518&top_category=12518&pageSize=20&orderBy=FAVOURITES_FIRST&searchTerm=&beginIndex=0&hideFilters=true';
$crawler = $client->request('GET', $url_crawl);
$product_elms = new Products();
$crawler->filter('ul.productLister > li .productInner')->each(function ($node) use(&$product_elms) {
    $product_elm = new Product();
    $product_elm->setTitle($node->filter('h3 a')->text());
    $product_elm->setUnitPrice($node->filter('.pricePerUnit')->text());
    // get the item description from the linked page
    $client_internal = new Client();
    $crawler_internal = $client_internal->request('GET', $node->filter('h3 a')->attr('href'));
    $product_elm->setDescription($crawler_internal->filter('.productText')->text());
    $product_elm->setSize(strlen($crawler_internal->html()));
    // calc total unit price
    $product_elms->add($product_elm)->addUnitPrice($product_elm);
});
ProductsOutputUtil::output('json', $product_elms);
Example #11
0
 /**
  * Populate product object 
  *
  * @param array $product
  * @return object 
  */
 protected function getProductObject($product)
 {
     if (empty($product)) {
         throw new BuyatException('Malformed response from server');
     }
     $productObject = new Product();
     $productObject->setProductID($product['product_id']);
     $productObject->setProductSKU($product['product_sku']);
     $productObject->setProductURL($product['product_url']);
     $productObject->setProductName($product['product_name']);
     $productObject->setBrandName($product['brand_name']);
     $productObject->setDescription($product['description']);
     $productObject->setOnlinePrice($product['online_price']);
     $productObject->setCurrency($product['currency']);
     $productObject->setCurrencySymbol($product['currency_symbol']);
     $productObject->setImageURL($product['image_url']);
     $productObject->setProgrammeName($product['programme_name']);
     $productObject->setProgrammeURL($product['programme_url']);
     $productObject->setProgrammeID($product['programme_id']);
     $productObject->setLevel1CategoryID($product['level1_category_id']);
     $productObject->setLevel1CategoryName($product['level1_category_name']);
     $productObject->setLevel2CategoryID($product['level2_category_id']);
     $productObject->setLevel2CategoryName($product['level2_category_name']);
     $productObject->setFeedID($product['feed_id']);
     $productObject->setFeedName($product['feed_name']);
     return $productObject;
 }
Example #12
0
require_once 'electronics.php';
if (isset($_POST['commit'])) {
    $title = $_POST['title'];
    $description = $_POST['description'];
    $price = $_POST['price'];
    $shipping = $_POST['shipping'];
    $weight = $_POST['weight'];
    $recyclable = $_POST['recyclable'];
    if (!empty($recyclable)) {
        $electronic = new Electronics();
        $electronic->setRecyclable($recyclable);
        $electronic->setTitle($title);
        $electronic->setPrice($price);
        $electronic->setDescription($description);
        $electronic->addDatabase();
    } elseif (!empty($shipping)) {
        $tool = new Tools();
        $tool->setTitle($title);
        $tool->setDescription($description);
        $tool->setPrice($price);
        $tool->setShipper($shipping);
        $tool->setWeight($weight);
        $tool->addDatabase();
    } else {
        $product = new Product();
        $product->setDescription($description);
        $product->setTitle($title);
        $product->setPrice($price);
        $product->addDatabase();
    }
}