protected function generateProductsData()
    {
        $delimiter = ';';
        $titles = array();
        $id_lang = $this->use_lang;
        $new_path = new Sampledatainstall();
        $f = fopen($new_path->sendPath() . 'output/products.vsc', 'w');
        foreach ($this->product_fields as $field => $array) {
            $titles[] = $array['label'];
        }
        fputcsv($f, $titles, $delimiter, '"');
        $products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', false, true);
        foreach ($products as $product) {
            $line = array();
            $p = new Product($product['id_product'], true, $id_lang, 1);
            foreach ($this->product_fields as $field => $array) {
                $line[$field] = property_exists('Product', $field) && !is_array($p->{$field}) && !Tools::isEmpty($p->{$field}) ? $p->{$field} : '';
            }
            $cats = $p->getProductCategoriesFull($p->id, 1);
            $cat_array = array();
            foreach ($cats as $cat) {
                $cat_array[] = $cat['id_category'];
            }
            $line['categories'] = implode(',', $cat_array);
            $line['price_tex'] = $p->getPrice(false);
            $line['price_tin'] = $p->getPrice(true);
            $line['upc'] = $p->upc ? $p->upc : '';
            $line['features'] = '';
            $features = $p->getFrontFeatures($id_lang);
            $position = 1;
            $devider = '';
            foreach ($features as $feature) {
                $sql = 'SELECT `id_feature`
						FROM ' . _DB_PREFIX_ . 'feature_lang
						WHERE `name` = "' . pSql($feature['name']) . '"';
                $sql1 = 'SELECT `id_feature_value`
						FROM ' . _DB_PREFIX_ . 'feature_value_lang
						WHERE `value` = "' . pSql($feature['value']) . '"';
                $id_feature = Db::getInstance()->getValue($sql);
                $id_feature_value = Db::getInstance()->getValue($sql1);
                $line['features'] .= $devider . $id_feature . ':' . $id_feature_value . ':' . $position;
                $devider = ',';
                $position++;
            }
            $specificPrice = SpecificPrice::getSpecificPrice($p->id, 1, 0, 0, 0, 0);
            $line['reduction_price'] = '';
            $line['reduction_percent'] = '';
            $line['reduction_from'] = '';
            $line['reduction_to'] = '';
            if ($specificPrice) {
                if ($specificPrice['reduction_type'] == 'amount') {
                    $line['reduction_price'] = $specificPrice['reduction'];
                } elseif ($specificPrice['reduction_type'] == 'percent') {
                    $line['reduction_percent'] = $specificPrice['reduction'];
                }
                if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') {
                    $line['reduction_from'] = $specificPrice['from'];
                    $line['reduction_to'] = $specificPrice['to'];
                }
            }
            $tags = $p->getTags($id_lang);
            $line['tags'] = $tags;
            $link = new Link();
            $imagelinks = array();
            $images = $p->getImages($id_lang);
            foreach ($images as $image) {
                $imagelink = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']);
                $this->copyConverFileName($imagelink);
                $imagelinks[] = $imagelink;
            }
            $line['image'] = implode(',', $imagelinks);
            $line['delete_existing_images'] = 0;
            $line['shop'] = 1;
            $warehouses = Warehouse::getWarehousesByProductId($p->id);
            $line['warehouse'] = '';
            if (!empty($warehouses)) {
                $line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses));
            }
            $values = array();
            $accesories = $p->getAccessories($id_lang);
            if (isset($accesories) && $accesories && count($accesories)) {
                foreach ($accesories as $accesorie) {
                    $values[] = $accesorie['id_product'];
                }
            }
            $line['accessories'] = $values ? implode(',', $values) : '';
            $values = array();
            $carriers = $p->getCarriers();
            if (isset($carriers) && $carriers && count($carriers)) {
                foreach ($carriers as $carrier) {
                    $values[] = $carrier['id_carrier'];
                }
            }
            $line['carriers'] = $values ? implode(',', $values) : '';
            $values = array();
            $customization_fields_ids = $p->getCustomizationFieldIds();
            if (class_exists('CustomizationField') && isset($customization_fields_ids) && $customization_fields_ids && count($customization_fields_ids)) {
                foreach ($customization_fields_ids as $customization_field_id) {
                    $cf = new CustomizationField($customization_field_id['id_customization_field'], $this->use_lang);
                    $values[] = $cf->id . ':' . $cf->type . ':' . $cf->required . ':' . $cf->name;
                }
            }
            $line['customization_fields_ids'] = $values ? implode(',', $values) : '';
            $values = array();
            $attachments = $p->getAttachments($this->use_lang);
            if (isset($attachments) && $attachments && count($attachments)) {
                foreach ($attachments as $attachment) {
                    $values[] = $attachment['id_attachment'];
                }
            }
            $line['attachments'] = $values ? implode(',', $values) : '';
            if (!property_exists('Product', 'base_price')) {
                // for versions < 1.6.0.13
                $line['base_price'] = !is_array($p->base_price) && !Tools::isEmpty($p->base_price) ? $p->base_price : '';
            }
            if (!$line[$field]) {
                $line[$field] = '';
            }
            fputcsv($f, $line, $delimiter, '"');
        }
        fclose($f);
    }
Example #2
0
 /**
  * Create a link to a product
  *
  * @param mixed $product Product object (can be an ID product, but deprecated)
  * @param string $alias
  * @param string $category
  * @param string $ean13
  * @param int $id_lang
  * @param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart
  * @param int $ipa ID product attribute
  * @return string
  */
 public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null, $ipa = 0, $force_routes = false, $relative_protocol = false)
 {
     $dispatcher = Dispatcher::getInstance();
     if (!$id_lang) {
         $id_lang = Context::getContext()->language->id;
     }
     $url = $this->getBaseLink($id_shop, null, $relative_protocol) . $this->getLangLink($id_lang, null, $id_shop);
     if (!is_object($product)) {
         if (is_array($product) && isset($product['id_product'])) {
             $product = new Product($product['id_product'], false, $id_lang, $id_shop);
         } elseif ((int) $product) {
             $product = new Product((int) $product, false, $id_lang, $id_shop);
         } else {
             throw new PrestaShopException('Invalid product vars');
         }
     }
     // Set available keywords
     $params = array();
     $params['id'] = $product->id;
     $params['rewrite'] = !$alias ? $product->getFieldByLang('link_rewrite') : $alias;
     $params['ean13'] = !$ean13 ? $product->ean13 : $ean13;
     $params['meta_keywords'] = Tools::str2url($product->getFieldByLang('meta_keywords'));
     $params['meta_title'] = Tools::str2url($product->getFieldByLang('meta_title'));
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'manufacturer', $id_shop)) {
         $params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'supplier', $id_shop)) {
         $params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'price', $id_shop)) {
         $params['price'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specificPrice);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'tags', $id_shop)) {
         $params['tags'] = Tools::str2url($product->getTags($id_lang));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'category', $id_shop)) {
         $params['category'] = !is_null($product->category) && !empty($product->category) ? Tools::str2url($product->category) : Tools::str2url($category);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'reference', $id_shop)) {
         $params['reference'] = Tools::str2url($product->reference);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'categories', $id_shop)) {
         $params['category'] = !$category ? $product->category : $category;
         $cats = array();
         foreach ($product->getParentCategories() as $cat) {
             if (!in_array($cat['id_category'], Link::$category_disable_rewrite)) {
                 //remove root and home category from the URL
                 $cats[] = $cat['link_rewrite'];
             }
         }
         $params['categories'] = implode('/', $cats);
     }
     $anchor = $ipa ? $product->getAnchor($ipa) : '';
     return $url . $dispatcher->createUrl('product_rule', $id_lang, $params, $force_routes, $anchor, $id_shop);
 }
Example #3
0
 /**
  * Builds the tag list for the product.
  *
  * Also includes the custom "add-to-cart" tag if the product can be added to the shopping cart directly without
  * any action from the user, e.g. the product cannot have any variations or choices. This tag is then used in the
  * recommendations to render the "Add to cart" button for the product when it is recommended to a user.
  *
  * @param Product $product the product model.
  * @param int $id_lang for which language ID to fetch the product tags.
  * @return array the built tags.
  */
 protected function buildTags(Product $product, $id_lang)
 {
     $tags = array();
     if (($product_tags = $product->getTags($id_lang)) !== '') {
         $tags = explode(', ', $product_tags);
     }
     // If the product has no attributes (color, size etc.), then we mark it as possible to add directly to cart.
     $product_attributes = $product->getAttributesGroups($id_lang);
     if (empty($product_attributes)) {
         $tags[] = self::ADD_TO_CART;
     }
     return $tags;
 }
Example #4
0
function addProducts($client, $ids = array())
{
    //update currency
    // update_currency();
    $default_tz = date_default_timezone_get();
    date_default_timezone_set('UTC');
    $category = new Category(1, 1);
    $sql = "select p.id_product, DATEDIFF(NOW(), p.`date_add`) as 'age'\n            from ps_product p\n            where p.price > 0 and p.active = 1";
    $productScores = array();
    $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
    foreach ($products as $product) {
        $productScores[$product['id_product']] = array('age' => $product['age'], 'week_sold' => 0, 'month_sales' => 0, 'year_sales' => 0);
    }
    $sql = "select p.`id_product`, sum(od.product_quantity) as 'quantity'\n            from `ps_product` p\n            inner join `ps_order_detail` od on od.product_id = p.id_product\n            inner join ps_orders o on o.id_order = od.id_order\n            where p.price > 0 \n            and p.active = 1\n            and o.date_add > now() - INTERVAL 7 DAY\n            group by p.id_product";
    $week_quantities = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
    foreach ($week_quantities as $week_quantity) {
        $productScores[$week_quantity['id_product']]['week_sold'] = $week_quantity['quantity'];
    }
    $sql = "select p.`id_product`, round(sum(od.product_quantity * od.product_price * 55 / o.`conversion_rate`)) as 'month_revenue'\n            from `ps_product` p\n            inner join `ps_order_detail` od on od.product_id = p.id_product\n            inner join ps_orders o on o.id_order = od.id_order\n            where p.price > 0 and p.active = 1\n            and o.date_add > now() - INTERVAL 30 DAY\n            group by p.id_product";
    $month_sales = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
    foreach ($month_sales as $month_sale) {
        $productScores[$month_sale['id_product']]['month_sales'] = $month_sale['month_revenue'];
    }
    $sql = "select p.`id_product`, round(sum(od.product_quantity * od.product_price * 55 / o.`conversion_rate`)) as 'year_revenue'\n            from `ps_product` p\n            inner join `ps_order_detail` od on od.product_id = p.id_product\n            inner join ps_orders o on o.id_order = od.id_order\n            where p.price > 0 and p.active = 1\n            and o.date_add > now() - INTERVAL 365 DAY\n            group by p.id_product";
    $year_sales = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
    foreach ($year_sales as $year_sale) {
        $productScores[$year_sale['id_product']]['year_sales'] = $year_sale['year_revenue'];
    }
    foreach ($products as $product) {
        $productScores[$product['id_product']]['score'] = getWeekSalesScore($productScores[$product['id_product']]['week_sold']) + getAgeScore($productScores[$product['id_product']]['age']) + getMonthScore($productScores[$product['id_product']]['month_sales']) + getYearScore($productScores[$product['id_product']]['year_sales']);
    }
    $docs = array();
    $link = new Link();
    $count = 0;
    $update = $client->createUpdate();
    foreach ($products as $product) {
        if (!empty($ids) && !in_array((int) $product['id_product'], $ids)) {
            continue;
        }
        $productObj = new Product((int) $product['id_product'], true, 1);
        print_r('\\n' . 'reindexing ' . $product['id_product']);
        if (!$productObj->active) {
            deleteProduct($productObj->id, $client);
            continue;
        }
        $doc = $update->createDocument();
        $doc->id_product = $productObj->id;
        $doc->reference = $productObj->reference;
        $doc->name = $productObj->name;
        $doc->description = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->description);
        $doc->description_short = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->description_short);
        $doc->brand_id = $productObj->id_manufacturer;
        $doc->brand_name = $productObj->manufacturer_name;
        $doc->style_tips = $productObj->description_short;
        $doc->alphaNameSort = $productObj->name;
        $dbresult = $productObj->getWsCategories();
        $catIds = array();
        foreach ($dbresult as $catIdRow) {
            $catIds[] = $catIdRow['id'];
        }
        $category_names = array();
        foreach ($catIds as $catID) {
            $category = new Category((int) $catID);
            $category_names[] = $category->getName(1);
        }
        $doc->cat_name = $category_names;
        $doc->cat_id = $catIds;
        $doc->tags = $productObj->getTags(1);
        $doc->shipping_sla = $productObj->shipping_sla ? $productObj->shipping_sla : 0;
        $doc->weight = $productObj->weight ? $productObj->weight : 0.5;
        if (isset($productObj->work_type)) {
            $doc->work_type = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->work_type ? $productObj->work_type : '');
        }
        if (isset($productObj->garment_type)) {
            $doc->garment_type = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->garment_type ? $productObj->garment_type : '');
        }
        if (isset($productObj->blouse_length)) {
            $doc->blouse_length = $productObj->blouse_length ? $productObj->blouse_length : '';
        }
        $doc->height = $productObj->height;
        $doc->width = $productObj->width;
        $atributeQty = Attribute::getAttributeQty($productObj->id);
        if ($productObj->quantity > 0 || $atributeQty > 0) {
            $doc->inStock = true;
        } else {
            $doc->inStock = false;
        }
        $doc->isPlusSize = $productObj->is_plussize ? true : false;
        $doc->isRTS = $productObj->is_rts ? true : false;
        $doc->quantity = $productObj->quantity ? $productObj->quantity : ($atributeQty ? $atributeQty : 0);
        //Indian Price
        $doc->offer_price_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, true, 1, false, NULL, NULL, IND_ADDRESS_ID);
        $doc->offer_price_in_rs = Tools::convertPrice($doc->offer_price_in, 4);
        $doc->mrp_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, false, 1, false, NULL, NULL, IND_ADDRESS_ID);
        if ($doc->mrp_in > $doc->offer_price_in) {
            $doc->discount_in = Tools::ps_round(($doc->mrp_in - $doc->offer_price_in) / $doc->mrp_in * 100);
        }
        //Worldwide Price
        $doc->offer_price = $productObj->getPrice();
        $doc->offer_price_rs = Tools::convertPrice($doc->offer_price, 4);
        $doc->mrp = $productObj->getPriceWithoutReduct();
        if ($doc->mrp > $doc->offer_price) {
            $doc->discount = Tools::ps_round(($doc->mrp - $doc->offer_price) / $doc->mrp * 100);
        }
        $date = DateTime::createFromFormat('Y-m-d H:i:s', $productObj->date_add);
        $doc->date_add = $date->format("Y-m-d\\TG:i:s\\Z");
        $doc->product_link = $productObj->getLink();
        $idImage = $productObj->getCoverWs();
        if ($idImage) {
            $idImage = $productObj->id . '-' . $idImage;
        } else {
            $idImage = Language::getIsoById(1) . '-default';
        }
        $doc->image_link_list = $link->getImageLink($productObj->link_rewrite, $idImage, 'list');
        $doc->image_link_medium = $link->getImageLink($productObj->link_rewrite, $idImage, 'medium');
        $doc->image_link_large = $link->getImageLink($productObj->link_rewrite, $idImage, 'large');
        $images = $productObj->getImages(1);
        $productImages = array();
        foreach ($images as $k => $image) {
            $productImages[] = $link->getImageLink($productObj->link_rewrite, $image['id_image'], 'large');
        }
        $doc->image_links = $productImages;
        $doc->sales = $productScores[$product['id_product']]['score'];
        $productObj->fabric = trim($productObj->fabric);
        $productObj->fabric = preg_replace('/\\s+/', '-', $productObj->fabric);
        $doc->fabric = strtolower($productObj->fabric);
        $doc->is_customizable = $productObj->is_customizable;
        if (isset($productObj->generic_color) && !empty($productObj->generic_color)) {
            $colors = explode(',', $productObj->generic_color);
            $indexed_colors = array();
            foreach ($colors as $color) {
                $indexed_colors[] = strtolower(preg_replace('/\\s+/', '-', trim($color)));
            }
            $doc->color = $indexed_colors;
        }
        if (isset($productObj->stone) && !empty($productObj->stone)) {
            $stones = explode(',', $productObj->stone);
            $indexed_stones = array();
            foreach ($stones as $stone) {
                $indexed_stones[] = strtolower(preg_replace('/\\s+/', '-', trim($stone)));
            }
            $doc->stone = $indexed_stones;
        }
        if (isset($productObj->plating) && !empty($productObj->plating)) {
            $platings = explode(',', $productObj->plating);
            $indexed_platings = array();
            foreach ($platings as $plating) {
                $indexed_platings[] = strtolower(preg_replace('/\\s+/', '-', trim($plating)));
            }
            $doc->plating = $indexed_platings;
        }
        if (isset($productObj->material) && !empty($productObj->material)) {
            $materials = explode(',', $productObj->material);
            $indexed_materials = array();
            foreach ($materials as $material) {
                $indexed_materials[] = strtolower(preg_replace('/\\s+/', '-', trim($material)));
            }
            $doc->material = $indexed_materials;
        }
        if (isset($productObj->look) && !empty($productObj->look)) {
            $looks = explode(',', $productObj->look);
            $indexed_looks = array();
            foreach ($looks as $look) {
                $indexed_looks[] = strtolower(preg_replace('/\\s+/', '-', trim($look)));
            }
            $doc->look = $indexed_looks;
        }
        if (isset($productObj->handbag_occasion) && !empty($productObj->handbag_occasion)) {
            $handbag_occasions = explode(',', $productObj->handbag_occasion);
            $indexed_handbag_occasions = array();
            foreach ($handbag_occasions as $handbag_occasion) {
                $indexed_handbag_occasions[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_occasion)));
            }
            $doc->handbag_occasion = $indexed_handbag_occasions;
        }
        if (isset($productObj->handbag_style) && !empty($productObj->handbag_style)) {
            $handbag_styles = explode(',', $productObj->handbag_style);
            $indexed_handbag_styles = array();
            foreach ($handbag_styles as $handbag_style) {
                $indexed_handbag_styles[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_style)));
            }
            $doc->handbag_style = $indexed_handbag_styles;
        }
        if (isset($productObj->handbag_material) && !empty($productObj->handbag_material)) {
            $handbag_materials = explode(',', $productObj->handbag_material);
            $indexed_handbag_materials = array();
            foreach ($handbag_materials as $handbag_material) {
                $indexed_handbag_materials[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_material)));
            }
            $doc->handbag_material = $indexed_handbag_materials;
        }
        $combinaisons = $productObj->getAttributeCombinaisons(1);
        $indexed_sizes = array();
        foreach ($combinaisons as $k => $combinaison) {
            if ($combinaison['group_name'] == 'size' || $combinaison['group_name'] == 'Size') {
                $indexed_sizes[] = $combinaison['attribute_name'];
            }
        }
        $doc->size = $indexed_sizes;
        $doc->cashback_percentage = $productObj->cashback_percentage;
        $docs[] = $doc;
        if (++$count == 300) {
            $update->addDocuments($docs);
            $result = $client->update($update);
            echo 'Update query executed' . PHP_EOL;
            echo 'Query status: ' . $result->getStatus() . PHP_EOL;
            echo 'Query time: ' . $result->getQueryTime() . PHP_EOL;
            $count = 0;
            $docs = array();
            $update = $client->createUpdate();
        }
    }
    $update->addDocuments($docs);
    date_default_timezone_set($default_tz);
    $result = $client->update($update);
    $sql = "update ps_product set indexed = 1 where indexed = 0";
    Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
}
 public function preProcess()
 {
     global $isVirtualCart, $cookie;
     parent::preProcess();
     // Redirect to the good order process
     if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 and (strpos($_SERVER['PHP_SELF'], 'order.php') === false and strpos($_SERVER['PHP_SELF'], 'cart-summary-large.php') === false)) {
         Tools::redirect('order.php');
     }
     if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 and strpos($_SERVER['PHP_SELF'], 'order-opc.php') === false) {
         if (isset($_GET['step']) and $_GET['step'] == 3) {
             Tools::redirect('order-opc.php?isPaymentStep=true');
         }
         Tools::redirect('order-opc.php');
     }
     if (Configuration::get('PS_CATALOG_MODE')) {
         $this->errors[] = Tools::displayError('This store has not accepted your new order.');
     }
     if (Tools::isSubmit('submitReorder') and $id_order = (int) Tools::getValue('id_order')) {
         $oldCart = new Cart(Order::getCartIdStatic((int) $id_order, (int) self::$cookie->id_customer));
         $duplication = $oldCart->duplicate();
         if (!$duplication or !Validate::isLoadedObject($duplication['cart'])) {
             $this->errors[] = Tools::displayError('Sorry, we cannot renew your order.');
         } elseif (!$duplication['success']) {
             $this->errors[] = Tools::displayError('Missing items - we are unable to renew your order');
         } else {
             self::$cookie->id_cart = $duplication['cart']->id;
             self::$cookie->write();
             if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) {
                 Tools::redirect('order-opc.php');
             }
             Tools::redirect('order.php');
         }
     }
     if (Tools::isSubmit('submit_instructions')) {
         $instructions = Tools::getValue('special_instructions');
         self::$cart->gift_message = pSQL($instructions);
         self::$cart->update();
         Tools::redirect('order?step=3');
     }
     if ($this->nbProducts) {
         /* check discount validity */
         $cartDiscounts = self::$cart->getDiscounts();
         $discountInvalid = false;
         foreach ($cartDiscounts as $k => $cartDiscount) {
             if ($error = self::$cart->checkDiscountValidity(new Discount((int) $cartDiscount['id_discount']), $cartDiscounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING), self::$cart->getProducts())) {
                 self::$cart->deleteDiscount((int) $cartDiscount['id_discount']);
                 $discountInvalid = true;
             }
         }
         if ($discountInvalid) {
             Tools::redirect('order-opc.php');
         }
         if (Tools::getValue('redeem_points')) {
             $points = (int) Tools::getValue('redeem_points');
             if ($points < 1) {
                 self::$smarty->assign('redeem_points', $points);
                 $this->errors[] = Tools::displayError('You can redeem minimum of 1 coin in an order.');
             }
             $orderTotal = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
             $redemption_status = VBRewards::checkPointsValidity($cookie->id_customer, $points + self::$cart->getPoints(), $orderTotal);
             if ($redemption_status === CAN_REDEEM_COINS) {
                 self::$cart->addPoints($points);
                 self::$smarty->assign('redeem_points', (int) self::$cart->getPoints());
             } else {
                 if ($redemption_status === INSUFFICIENT_VALID_ORDERS) {
                     $this->errors[] = Tools::displayError('Coins can be redeemed from second purchase onwards.');
                 } else {
                     if ($redemption_status === MIN_CRITERIA_NOT_MET) {
                         $this->errors[] = Tools::displayError('Order value should be more than 100 USD to redeem coins');
                     }
                 }
             }
             $this->adjustPoints();
         } elseif (Tools::getValue('deletePoints')) {
             self::$cart->deletePoints();
         }
         if (Tools::isSubmit('submitAddDiscount') and Tools::getValue('discount_name')) {
             $discountName = Tools::getValue('discount_name');
             if (!Validate::isDiscountName($discountName)) {
                 $this->errors[] = Tools::displayError('Voucher name invalid.');
             } else {
                 $discount = new Discount((int) Discount::getIdByName($discountName));
                 if (Validate::isLoadedObject($discount)) {
                     if ($tmpError = self::$cart->checkDiscountValidity($discount, self::$cart->getDiscounts(), self::$cart->getOrderTotal(), self::$cart->getProducts(), true)) {
                         $this->errors[] = $tmpError;
                     }
                 } else {
                     $this->errors[] = Tools::displayError('Voucher name invalid.');
                 }
                 if (!sizeof($this->errors)) {
                     self::$cart->addDiscount((int) $discount->id);
                     Tools::redirect('order-opc.php');
                 }
             }
             self::$smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName)));
             $this->adjustPoints();
         } elseif (isset($_GET['deleteDiscount']) and Validate::isUnsignedId($_GET['deleteDiscount'])) {
             self::$cart->deleteDiscount((int) $_GET['deleteDiscount']);
             Tools::redirect('order-opc.php');
         }
         /* Is there only virtual product in cart */
         if ($isVirtualCart = self::$cart->isVirtualCart()) {
             $this->_setNoCarrier();
         }
     }
     //if enough stock, show free gift message
     $free_products = array(66254, 66255, 66256);
     $sql = "select quantity from ps_product where id_product in (" . implode(",", $free_products) . ")";
     $result = Db::getInstance()->ExecuteS($sql);
     $free_gift_stock = $has_free_gift = false;
     foreach ($result as $row) {
         if (intval($row['quantity']) > 0) {
             $free_gift_stock = true;
             break;
         }
     }
     $total_products_wt = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
     $cv = Tools::convertPrice($total_products_wt, (int) self::$cookie->id_currency, false);
     /*if( $cv > 50) {	
     		if( $free_gift_stock ) {
     			$cart_products = self::$cart->getProducts();
     			foreach($cart_products as $cproduct) {
     				$id_product = $cproduct['id_product'];
     				if( in_array($id_product, $free_products )) {
     					$has_free_gift = true;
     					break;	
     				}
     			}
     		}
     		if( !$has_free_gift && $free_gift_stock ) {
     			self::$smarty->assign("spl_voucher_message","Here is the free <a href='/1222-free-gifts'>gift product</a> for you.Valid still stock lasts. Read <a href='/content/30-womens-day-special-discount'>T&C</a> here");
     		}
     	} else {
     		$free_products = array(66254, 66255, 66256);
     		foreach($free_products as $p)
     			self::$cart->deleteProduct($p);
     		self::$smarty->assign("spl_voucher_message","We have a free <a href='/1222-free-gifts'>gift product</a> for you if the shopping cart value is atleast USD 50.");
     	}
             self::$smarty->assign('back', Tools::safeOutput(Tools::getValue('back')));
     
             if (self::$cart->gift_message) {
                 self::$smarty->assign('cart_instructions', 1);
                 self::$smarty->assign('special_instructions', self::$cart->gift_message);
             }*/
     //buy1 get 1
     $products = self::$cart->getProducts(true);
     $offeredProducts = 0;
     // this is a very interesting array, keeps as many rows as there are items in your cart
     // if there is an item with quantity 2, it will have two rows in that array,
     // ie item will have as many rows as the quantity of the item in cart.
     $offerproducts = array();
     foreach ($products as $product) {
         $productObj = new Product($product['id_product'], true);
         $tags = $productObj->getTags(1);
         //print_r($productObj);
         if (in_array('buy1get1', $tags)) {
             self::$smarty->assign("spl_voucher_message", "You are eligible for Buy 1 Get 1 Offer");
             //counting the b1g1 products
             $offeredProducts = $offeredProducts + $product['cart_quantity'];
         } else {
             if (in_array('buy2get3', $tags)) {
                 self::$smarty->assign("spl_voucher_message", "You are eligible for buy 3 pay for 2 offer");
                 //counting the b1g1 products
                 $offeredProducts = $offeredProducts + $product['cart_quantity'];
             }
         }
         //adding rows to interesting array $b1g1products
         for ($q = 0; $q < $product['cart_quantity']; $q++) {
             array_push($offerproducts, $product);
         }
     }
     //sorting products in ascending order of price
     usort($offerproducts, function ($prod1, $prod2) {
         return $prod1['price'] - $prod2['price'];
     });
     ///echo "<pre>";print_r($offerproducts);
     if (in_array('buy1get1', $tags)) {
         $noOfferedAdvantageAvailable = (int) ($offeredProducts / 2);
     } elseif (in_array('buy2get3', $tags)) {
         $noOfferedAdvantageAvailable = (int) ($offeredProducts / 3);
     }
     $discount = 0;
     for ($p = 0; $p < $noOfferedAdvantageAvailable; $p++) {
         //print_r("offerproducts".$offerproducts[$p]['price']);
         $discount = $discount + $offerproducts[$p]['price'];
         //print_r($discount);
     }
     if ((int) self::$cart->id_currency != 2) {
         $discount = Tools::convertPrice($discount, (int) self::$cart->id_currency, false);
     }
     $discount = round($discount, 2);
     $b1g1DiscountInCart = null;
     $b2g3DiscountInCart = null;
     $allCartDiscounts = self::$cart->getDiscounts();
     //print_r($allCartDiscounts);
     foreach ($allCartDiscounts as $cartDiscount) {
         if (strpos($cartDiscount['name'], 'B1G1') === 0) {
             $b1g1DiscountInCart = new Discount((int) Discount::getIdByName($cartDiscount['name']));
             //echo "buy1get1";
         } else {
             if (strpos($cartDiscount['name'], 'B2G3') === 0) {
                 $b2g3DiscountInCart = new Discount((int) Discount::getIdByName($cartDiscount['name']));
                 //echo "buy2get3";
             }
         }
     }
     if (in_array('buy1get1', $tags)) {
         if ($discount > 0 && empty($b1g1DiscountInCart)) {
             $new_discount = new Discount();
             $new_discount->id_discount_type = 2;
             $new_discount->value = $discount;
             // coupon value
             $new_discount->name = "B1G1" . Tools::rand_string(5);
             $new_discount->id_currency = 2;
             $new_discount->quantity = 1;
             $new_discount->quantity_per_user = 0;
             $new_discount->date_from = date('Y-m-d H:i:s');
             $new_discount->date_to = '2015-08-10 20:00:00';
             //validity
             $new_discount->cumulable_reduction = 1;
             $languages = Language::getLanguages();
             foreach ($languages as $language) {
                 $new_discount->description[$language['id_lang']] = "Buy1 Get1";
             }
             // coupon description
             $new_discount->add();
             $id_discount = Discount::getIdByName($new_discount->name);
             self::$cart->addDiscount($id_discount);
         } else {
             if (!empty($b1g1DiscountInCart)) {
                 $b1g1DiscountInCart->value = (double) $discount;
                 // coupon value
                 if ($b1g1DiscountInCart->value > 0) {
                     $b1g1DiscountInCart->update();
                 } else {
                     $b1g1DiscountInCart->delete();
                 }
             }
         }
     } else {
         if (in_array('buy2get3', $tags)) {
             if ($discount > 0 && empty($b2g3DiscountInCart)) {
                 $new_discount = new Discount();
                 $new_discount->id_discount_type = 2;
                 $new_discount->value = $discount;
                 // coupon value
                 $new_discount->name = "B2G3" . Tools::rand_string(5);
                 $new_discount->id_currency = 2;
                 $new_discount->quantity = 1;
                 $new_discount->quantity_per_user = 0;
                 $new_discount->date_from = date('Y-m-d H:i:s');
                 $new_discount->date_to = '2015-08-10 20:00:00';
                 //validity
                 $new_discount->cumulable_reduction = 1;
                 $languages = Language::getLanguages();
                 foreach ($languages as $language) {
                     $new_discount->description[$language['id_lang']] = "Buy2 Get3";
                 }
                 // coupon description
                 $new_discount->add();
                 $id_discount = Discount::getIdByName($new_discount->name);
                 self::$cart->addDiscount($id_discount);
             } else {
                 if (!empty($b2g3DiscountInCart)) {
                     $b2g3DiscountInCart->value = (double) $discount;
                     // coupon value
                     if ($b2g3DiscountInCart->value > 0) {
                         $b2g3DiscountInCart->update();
                     } else {
                         $b2g3DiscountInCart->delete();
                     }
                 }
             }
         }
     }
     /*//pick3pay2
              $products = self::$cart->getProducts(true);
              //print_r($products);
     
              $nP3P2Products = 0;
             
             // this is a very interesting array, keeps as many rows as there are items in your cart
             // if there is an item with quantity 2, it will have two rows in that array, 
             // ie item will have as many rows as the quantity of the item in cart.
             $p3p2products = array();
             foreach($products as $product) {   
                 $productObj = new Product($product['id_product'], true);
                 $tags = $productObj->getTags(1);
                 if(in_array('pick3pay2', $tags)){
                     self::$smarty->assign("spl_voucher_message", "Pick 3 and Pay for 2 only offer");
                     $nP3P2Products = $nP3P2Products + $product['cart_quantity'];
                     
                     for($q = 0; $q < $product['cart_quantity']; $q++){
                         array_push($p3p2products, $product);
                     }  
                 }
             }
     
            
             
             //sorting products in ascending order of price
             usort($p3p2products, function($prod1, $prod2){
                 return $prod1['price'] - $prod2['price'];
             });
     
             $noP3P2AdvantageAvailable = (int)($nP3P2Products/3);
             print_r($noP3P2AdvantageAvailable);
             $discount = 0;
             for($p = 0; $p < $noP3P2AdvantageAvailable; $p++){
                 $discount = $discount + $p3p2products[$p]['price'];
             }
     
             if((int)self::$cart->id_currency != 2){
                 $discount = Tools::convertPrice($discount, (int)self::$cart->id_currency, false);
             }
             
             $discount = round($discount, 2);
     
             $p3p2DiscountInCart = null;
             $allCartDiscounts = self::$cart->getDiscounts();
     
             foreach ($allCartDiscounts as $cartDiscount) {
                 //print_r($cartDiscount);print_r('<br/>');die;
                 if(strpos('P3P2', $cartDiscount['name']) == 0){
                     $p3p2DiscountInCart = new Discount((int) (Discount::getIdByName($cartDiscount['name'])));
                 }
             }
             
             if($discount > 0 && empty($p3p2DiscountInCart)){
                 $new_discount = new Discount();
                 $new_discount->id_discount_type = 2;
                 $new_discount->value = $discount; // coupon value
                 $new_discount->name = "P3P2" . Tools::rand_string(5);
                 $new_discount->id_currency = 2;
                 $new_discount->quantity = 1;
                 $new_discount->quantity_per_user = 100;
                 $new_discount->date_from = date('Y-m-d H:i:s');
                 $new_discount->date_to = '2015-09-10 20:00:00'; //validity
                 $new_discount->cumulable_reduction = 1;
                 $languages = Language::getLanguages();
                 foreach ($languages as $language)
                     $new_discount->description[$language['id_lang']] = "Pick3 Pay2"; // coupon description
                 
                 $new_discount->add();
                 $id_discount = Discount::getIdByName($new_discount->name);
                 print_r($id_discount);
                 self::$cart->addDiscount($id_discount);
                 
             }else if(!empty($p3p2DiscountInCart)){
                 $p3p2DiscountInCart->value = (float) $discount; // coupon value
                 if($p3p2DiscountInCart->value > 0)
                     $p3p2DiscountInCart->update();
                 else
                     $p3p2DiscountInCart->delete();
             }*/
 }
 public function postProcess()
 {
     if (Tools::isSubmit('submitExport')) {
         $delimiter = Tools::getValue('export_delimiter');
         $id_lang = Tools::getValue('export_language');
         $id_shop = (int) $this->context->shop->id;
         set_time_limit(0);
         $fileName = 'products_' . date("Y_m_d_H_i_s") . '.csv';
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header('Content-Description: File Transfer');
         header("Content-type: text/csv");
         header("Content-Disposition: attachment; filename={$fileName}");
         header("Expires: 0");
         header("Pragma: public");
         $f = fopen('php://output', 'w');
         foreach ($this->available_fields as $field => $array) {
             $titles[] = $array['label'];
         }
         fputcsv($f, $titles, $delimiter, '"');
         $export_active = Tools::getValue('export_active') == 0 ? false : true;
         $export_category = Tools::getValue('export_category') == 99999 ? false : Tools::getValue('export_category');
         $products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', $export_category, $export_active);
         foreach ($products as $product) {
             $line = array();
             $p = new Product($product['id_product'], true, $id_lang, $id_shop);
             $p->loadStockData();
             foreach ($this->available_fields as $field => $array) {
                 if (isset($p->{$field}) && !is_array($p->{$field})) {
                     $line[$field] = $p->{$field} ? $p->{$field} : ' ';
                 } else {
                     switch ($field) {
                         case 'categories':
                             $cats = $p->getProductCategoriesFull($p->id, $id_lang);
                             $cat_array = array();
                             foreach ($cats as $cat) {
                                 $cat_array[] = $cat['name'];
                             }
                             $line['categories'] = implode(",", $cat_array);
                             break;
                         case 'price_tex':
                             $line['price_tex'] = $p->getPrice(false);
                             $line['price_tin'] = $p->getPrice(true);
                             break;
                         case 'upc':
                             $line['upc'] = $p->upc ? $p->upc : ' ';
                             break;
                         case 'features':
                             $line['features'] = '';
                             $features = $p->getFrontFeatures($id_lang);
                             $position = 1;
                             foreach ($features as $feature) {
                                 $line['features'] .= $feature['name'] . ':' . $feature['value'] . ':' . $position;
                                 $position++;
                             }
                             break;
                         case 'reduction_price':
                             $specificPrice = SpecificPrice::getSpecificPrice($p->id, $id_shop, 0, 0, 0, 0);
                             $line['reduction_price'] = '';
                             $line['reduction_percent'] = '';
                             $line['reduction_from'] = '';
                             $line['reduction_to'] = '';
                             if ($specificPrice['reduction_type'] == "amount") {
                                 $line['reduction_price'] = $specificPrice['reduction'];
                             } elseif ($specificPrice['reduction_type'] == "percent") {
                                 $line['reduction_percent'] = $specificPrice['reduction'];
                             }
                             if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') {
                                 $line['reduction_from'] = date_format(date_create($specificPrice['from']), "Y-m-d");
                                 $line['reduction_to'] = date_format(date_create($specificPrice['to']), "Y-m-d");
                             }
                             break;
                         case 'tags':
                             $tags = $p->getTags($id_lang);
                             $line['tags'] = $tags;
                             break;
                         case 'image':
                             $link = new Link();
                             $imagelinks = array();
                             $images = $p->getImages($id_lang);
                             foreach ($images as $image) {
                                 $imagelinks[] = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']);
                             }
                             $line['image'] = implode(",", $imagelinks);
                             break;
                         case 'delete_existing_images':
                             $line['delete_existing_images'] = 0;
                             break;
                         case 'shop':
                             $line['shop'] = $id_shop;
                             break;
                         case 'warehouse':
                             $warehouses = Warehouse::getWarehousesByProductId($p->id);
                             $line['warehouse'] = '';
                             if (!empty($warehouses)) {
                                 $line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses));
                             }
                             break;
                         case 'date_added':
                             $date = new DateTime($p->date_add);
                             $line['date_add'] = $date->format("Y-m-d");
                             break;
                     }
                 }
             }
             if (!$line[$field]) {
                 $line[$field] = '';
             }
             fputcsv($f, $line, $delimiter, '"');
         }
         fclose($f);
         die;
     }
 }
Example #7
0
 /**
  * @param Solarium_Query_Update $update
  * @param Link $link
  * @param Product $productObj
  * @return Solarium_Document_ReadWrite
  */
 private static function getProductDoc($update, $link, $productObj)
 {
     $doc = $update->createDocument();
     $doc->id_product = $productObj->id;
     $doc->reference = $productObj->reference;
     $doc->name = $productObj->name;
     //$doc->description = $productObj->description;
     $doc->description = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->description);
     $doc->description_short = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->description_short);
     $doc->brand_id = $productObj->id_manufacturer;
     $doc->brand_name = $productObj->manufacturer_name;
     $doc->style_tips = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->description_short);
     $doc->alphaNameSort = $productObj->name;
     $dbresult = $productObj->getWsCategories();
     $catIds = array();
     foreach ($dbresult as $catIdRow) {
         $catIds[] = $catIdRow['id'];
     }
     $category_names = array();
     foreach ($catIds as $catID) {
         $category = new Category((int) $catID);
         $category_names[] = $category->getName(1);
     }
     $doc->cat_name = $category_names;
     $doc->cat_id = $catIds;
     $doc->tags = $productObj->getTags(1);
     $doc->shipping_sla = $productObj->shipping_sla;
     $doc->weight = $productObj->weight ? $productObj->weight : 0.5;
     $doc->cashback_percentage = $productObj->cashback_percentage;
     if (isset($productObj->work_type)) {
         $doc->work_type = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->work_type ? $productObj->work_type : '');
     }
     if (isset($productObj->garment_type)) {
         $doc->garment_type = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->garment_type ? $productObj->garment_type : '');
     }
     if (isset($productObj->blouse_length)) {
         $doc->blouse_length = $productObj->blouse_length ? $productObj->blouse_length : '';
     }
     $doc->height = $productObj->height;
     $doc->width = $productObj->width;
     $atributeQty = Attribute::getAttributeQty($productObj->id);
     if ($productObj->quantity > 0 || $atributeQty > 0) {
         $doc->inStock = true;
     } else {
         $doc->inStock = false;
     }
     $doc->isPlusSize = $productObj->is_plussize ? true : false;
     $doc->isRTS = $productObj->is_rts ? true : false;
     $doc->quantity = $productObj->quantity ? $productObj->quantity : ($atributeQty ? $atributeQty : 0);
     $date = DateTime::createFromFormat('Y-m-d H:i:s', $productObj->date_add);
     $doc->date_add = $date->format("Y-m-d\\TG:i:s\\Z");
     $productObj->fabric = trim($productObj->fabric);
     $productObj->fabric = preg_replace('/\\s+/', '-', $productObj->fabric);
     $doc->fabric = strtolower($productObj->fabric);
     $doc->is_customizable = $productObj->is_customizable;
     if (isset($productObj->generic_color) && !empty($productObj->generic_color)) {
         $colors = explode(',', $productObj->generic_color);
         $indexed_colors = array();
         foreach ($colors as $color) {
             $indexed_colors[] = strtolower(preg_replace('/\\s+/', '-', trim($color)));
         }
         $doc->color = $indexed_colors;
     }
     if (isset($productObj->stone) && !empty($productObj->stone)) {
         $stones = explode(',', $productObj->stone);
         $indexed_stones = array();
         foreach ($stones as $stone) {
             $indexed_stones[] = strtolower(preg_replace('/\\s+/', '-', trim($stone)));
         }
         $doc->stone = $indexed_stones;
     }
     if (isset($productObj->plating) && !empty($productObj->plating)) {
         $platings = explode(',', $productObj->plating);
         $indexed_platings = array();
         foreach ($platings as $plating) {
             $indexed_platings[] = strtolower(preg_replace('/\\s+/', '-', trim($plating)));
         }
         $doc->plating = $indexed_platings;
     }
     if (isset($productObj->material) && !empty($productObj->material)) {
         $materials = explode(',', $productObj->material);
         $indexed_materials = array();
         foreach ($materials as $material) {
             $indexed_materials[] = strtolower(preg_replace('/\\s+/', '-', trim($material)));
         }
         $doc->material = $indexed_materials;
     }
     if (isset($productObj->look) && !empty($productObj->look)) {
         $looks = explode(',', $productObj->look);
         $indexed_looks = array();
         foreach ($looks as $look) {
             $indexed_looks[] = strtolower(preg_replace('/\\s+/', '-', trim($look)));
         }
         $doc->look = $indexed_looks;
     }
     if (isset($productObj->handbag_occasion) && !empty($productObj->handbag_occasion)) {
         $handbag_occasions = explode(',', $productObj->handbag_occasion);
         $indexed_handbag_occasions = array();
         foreach ($handbag_occasions as $handbag_occasion) {
             $indexed_handbag_occasions[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_occasion)));
         }
         $doc->handbag_occasion = $indexed_handbag_occasions;
     }
     if (isset($productObj->handbag_style) && !empty($productObj->handbag_style)) {
         $handbag_styles = explode(',', $productObj->handbag_style);
         $indexed_handbag_styles = array();
         foreach ($handbag_styles as $handbag_style) {
             $indexed_handbag_styles[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_style)));
         }
         $doc->handbag_style = $indexed_handbag_styles;
     }
     if (isset($productObj->handbag_material) && !empty($productObj->handbag_material)) {
         $handbag_materials = explode(',', $productObj->handbag_material);
         $indexed_handbag_materials = array();
         foreach ($handbag_materials as $handbag_material) {
             $indexed_handbag_materials[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_material)));
         }
         $doc->handbag_material = $indexed_handbag_materials;
     }
     $combinaisons = $productObj->getAttributeCombinaisons(1);
     $indexed_sizes = array();
     foreach ($combinaisons as $k => $combinaison) {
         if ($combinaison['group_name'] == 'size' || $combinaison['group_name'] == 'Size') {
             $indexed_sizes[] = $combinaison['attribute_name'];
         }
     }
     $doc->size = $indexed_sizes;
     //Indian Price
     $doc->offer_price_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, true, 1, false, NULL, NULL, IND_ADDRESS_ID);
     $doc->offer_price_in_rs = Tools::convertPrice($doc->offer_price_in, 4);
     $doc->mrp_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, false, 1, false, NULL, NULL, IND_ADDRESS_ID);
     if ($doc->mrp_in > $doc->offer_price_in) {
         $doc->discount_in = Tools::ps_round(($doc->mrp_in - $doc->offer_price_in) / $doc->mrp_in * 100);
     }
     //Worldwide Price
     $doc->offer_price = $productObj->getPrice();
     $doc->offer_price_rs = Tools::convertPrice($doc->offer_price, 4);
     $doc->mrp = $productObj->getPriceWithoutReduct();
     if ($doc->mrp > $doc->offer_price) {
         $doc->discount = Tools::ps_round(($doc->mrp - $doc->offer_price) / $doc->mrp * 100);
     }
     $doc->product_link = $productObj->getLink();
     $idImage = $productObj->getCoverWs();
     if ($idImage) {
         $idImage = $productObj->id . '-' . $idImage;
     } else {
         $idImage = Language::getIsoById(1) . '-default';
     }
     $doc->image_link_list = $link->getImageLink($productObj->link_rewrite, $idImage, 'list');
     $doc->image_link_medium = $link->getImageLink($productObj->link_rewrite, $idImage, 'medium');
     $doc->image_link_large = $link->getImageLink($productObj->link_rewrite, $idImage, 'large');
     $images = $productObj->getImages(1);
     $productImages = array();
     foreach ($images as $k => $image) {
         $productImages[] = $link->getImageLink($productObj->link_rewrite, $image['id_image'], 'large');
     }
     $doc->image_links = $productImages;
     return $doc;
 }