/**
  * Management of search
  *
  */
 public function manage()
 {
     if (!isset($this->wsObject->urlFragments['query']) || !isset($this->wsObject->urlFragments['language'])) {
         throw new WebserviceException('You have to set both the \'language\' and \'query\' parameters to get a result', array(100, 400));
     }
     $objects_products = array();
     $objects_categories = array();
     $objects_products['empty'] = new Product();
     $objects_categories['empty'] = new Category();
     $this->_resourceConfiguration = $objects_products['empty']->getWebserviceParameters();
     if (!$this->wsObject->setFieldsToDisplay()) {
         return false;
     }
     $results = Search::find($this->wsObject->urlFragments['language'], $this->wsObject->urlFragments['query'], 1, 1, 'position', 'desc', true, false);
     $categories = array();
     foreach ($results as $result) {
         $current = new Product($result['id_product']);
         $objects_products[] = $current;
         $categories_result = $current->getWsCategories();
         foreach ($categories_result as $category_result) {
             foreach ($category_result as $id) {
                 $categories[] = $id;
             }
         }
     }
     $categories = array_unique($categories);
     foreach ($categories as $id) {
         $objects_categories[] = new Category($id);
     }
     $this->output .= $this->objOutput->getContent($objects_products, null, $this->wsObject->fieldsToDisplay, $this->wsObject->depth, WebserviceOutputBuilder::VIEW_LIST, false);
     // @todo allow fields of type category and product
     // $this->_resourceConfiguration = $objects_categories['empty']->getWebserviceParameters();
     // if (!$this->setFieldsToDisplay())
     // return false;
     $this->output .= $this->objOutput->getContent($objects_categories, null, $this->wsObject->fieldsToDisplay, $this->wsObject->depth, WebserviceOutputBuilder::VIEW_LIST, false);
 }
 /**
  * Updates a product on Prestashop.
  * 
  * @param array $product_attributes
  * @param integer $id_product
  * @param string $url_photo
  * @param array $triple_cod_col_siz
  * @param integer $language
  * @param array $array_combinations
  * @return array
  * @see $this->isOldNameProductEgualToNewNameProduct
  * @see $this->isOldOrNewValueForProduct
  * @see $this->controlCategoriesForActivateTheir 
  * @see $this->updateCombinantionsForPrestashop
  *
  */
 public function updateProductForPrestashop($product_attributes = array(), $id_product, $url_photo, $triple_cod_col_siz, $array_combinations, $language = 1)
 {
     $product = new Product($id_product);
     $is_change_product = false;
     $new_name_product = trim($product_attributes["Nome"]);
     if (!$this->isOldNameProductEgualToNewNameProduct($product->name, $new_name_product)) {
         $product->name = $this->setArrayElementForLinkRewrite($new_name_product, true, $language);
         $product->meta_keywords = $new_name_product;
         $product->link_rewrite = $this->setArrayElementForLinkRewrite($new_name_product, false, $language);
         $is_change_product = true;
     }
     $new_price = (double) $product_attributes["Prezzo"];
     if (!$this->isOldOrNewValueForProduct((double) $product->price, $new_price)) {
         $product->price = $new_price;
         $is_change_product = true;
     }
     $new_active = (int) $product_attributes["Attivo"];
     $control_category = $this->isOldOrNewValueForProduct((int) $product->active, $new_active);
     if (!$control_category) {
         $product->active = $new_active;
         $is_change_product = true;
     }
     $new_minimal_quantity = (int) $product_attributes["Qta_min"];
     if (!$this->isOldOrNewValueForProduct((int) $product->minimal_quantity, $new_minimal_quantity)) {
         $product->minimal_quantity = $new_minimal_quantity;
         $is_change_product = true;
     }
     $new_quantity = (int) $product_attributes["Qta"];
     if (!$this->isOldOrNewValueForProduct((int) $product->getQuantity($id_product), $new_quantity)) {
         StockAvailable::setQuantity($id_product, 0, $new_quantity);
     }
     $array_old_features = $product->getFeatures();
     $array_features = $product_attributes["Feature"];
     $height = false;
     $width = false;
     foreach ($array_old_features as $array_old_single_features) {
         $feature = new FeatureCore((int) $array_old_single_features['id_feature']);
         $tmp_feature = $feature->name;
         $single_old_feature = $tmp_feature[$language];
         $feature_value = new FeatureValueCore((int) $array_old_single_features["id_feature_value"]);
         $tmp_feature_value = $feature_value->value;
         $single_old_feature_value = $tmp_feature_value[$language];
         if ($this->isOldOrNewValueForProduct("Altezza", $single_old_feature)) {
             if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Altezza"] . " cm")) {
                 $feature_value->value = array($language => $array_features["Altezza"] . " cm");
                 $feature_value->update();
                 $height = true;
                 $is_change_product = true;
             }
         }
         if ($this->isOldOrNewValueForProduct("Larghezza", $single_old_feature)) {
             if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Larghezza"] . " cm")) {
                 $feature_value->value = array($language => $array_features["Larghezza"] . " cm");
                 $feature_value->update();
                 $width = true;
                 $is_change_product = true;
             }
         }
         if ($this->isOldOrNewValueForProduct("Lunghezza", $single_old_feature)) {
             if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Lunghezza"] . " cm")) {
                 $feature_value->value = array($language => $array_features["Lunghezza"] . " cm");
                 $feature_value->update();
                 $is_change_product = true;
             }
         }
         if ($this->isOldOrNewValueForProduct("Modello", $single_old_feature)) {
             if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Modello"])) {
                 $feature_value->value = array($language => $array_features["Modello"]);
                 $feature_value->update();
                 $is_change_product = true;
             }
         }
         if ($this->isOldOrNewValueForProduct("Linea", $single_old_feature)) {
             if (!$this->isOldOrNewValueForProduct($single_old_feature_value, $array_features["Linea"])) {
                 $feature_value->value = array($language => $array_features["Linea"]);
                 $feature_value->update();
                 $is_change_product = true;
             }
         }
     }
     if ($height) {
         $product->height = (double) $array_features["Altezza"];
         $is_change_product = true;
     }
     if ($width) {
         $product->width = (double) $array_features["Larghezza"];
         $is_change_product = true;
     }
     if ($is_change_product) {
         $product->update();
     }
     if (!$control_category) {
         $ids_categories_array = $product->getWsCategories();
         $this->controlCategoriesForActivateTheir($ids_categories_array);
     }
     $change_new_image = $this->updateCombinantionsForPrestashop($id_product, $url_photo, $triple_cod_col_siz, $array_combinations, $language);
     $string_triple = array();
     $return = array();
     array_push($return, $product->id);
     $array_images_combinations_of_the_product = $product->getImages($language);
     $element = array();
     foreach ($array_images_combinations_of_the_product as $array_combo_image) {
         $name_of_the_image = $array_combo_image['legend'];
         $id_image_of_the_product = $array_combo_image['id_image'];
         array_push($element, $id_image_of_the_product . ";" . $name_of_the_image);
     }
     array_push($return, $element);
     foreach ($change_new_image as $array_combo_image) {
         $fetch_tmp = explode(";", $array_combo_image);
         $fetch_jpg = explode(".jpg", $fetch_tmp[1]);
         $fetch_image_name = explode(",", $fetch_jpg[0]);
         array_push($string_triple, $fetch_image_name[2]);
     }
     array_push($return, $change_new_image);
     array_push($return, $string_triple);
     return $return;
 }
Example #3
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);
}
Example #4
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;
 }