Code changes to show Seller Name on cart and blockcart

In this board, we will periodically list various tips and tricks we find that may help in your use of PrestaShop. This will also include tips on the use of Agile modules. If you have a great tip, fix, or workaround for a PrestaShop feature, feel free to post it here...

Code changes to show Seller Name on cart and blockcart

Postby carlo.macis_15320 » Tue Mar 07, 2017 5:49 pm

//---------------------------------------------------------
// Show the seller name on the cart & blockcart on your agile marketplace.
//
// 1) Back up your files before you change anything;
// 2) I use Prestashop 1.6.1.4 + AgileMultipleSeller 3.3.1 + AgileSellerShipping, you may need to change something to make it work;
// 3) If you don't have AgileSellerShipping installed just ignore the last template snippet hookextracarrier.tpl
// 4) Note when you upgrade your agilemultipleseller module, your changes will disappear;
// 5) As always before changing anything back up everything, turn on debug mode if you get a blank page;
//---------------------------------------------------------

//-------------------------------------------------------------
// Add the following function to the override class, not the core class.
//-------------------------------------------------------------

override/classes/Cart.php

Code: Select all
/**
* Return cart products with seller details sorted by seller_name
* to display on shopping cart & blockcart
*
* carlo at EggBay.it
*
* @result array Products
*/
public function getProducts($refresh = false, $id_product = false, $id_country = null)
{
    if (!$this->id) { return array(); }
   $this->_products = parent::getProducts($refresh, $id_product, $id_country);
   if (empty($this->_products)) { return array(); }
   if(!Module::isInstalled('agilemultipleseller')) return $this->_products;
   $context = Context::getContext();
   $sql = '             
      SELECT distinct IFNULL(po.id_owner,0) AS id_seller,
      IFNULL(cp.id_product,0) AS id_product,   
      CASE WHEN IFNULL(sl.`company`,\'\')=\'\' THEN CONCAT(e.firstname,\' \', e.lastname) ELSE sl.`company` END AS seller_name,
      IFNULL(sl.`address1`,\'\') AS seller_add1,
      IFNULL(sl.`address2`,\'\') AS seller_add2,
      IFNULL(sl.`city`,\'\') AS seller_city           
      FROM ' . _DB_PREFIX_ . 'cart_product cp                   
      LEFT JOIN ' . _DB_PREFIX_ . 'product_owner po ON cp.id_product=po.id_product                   
      LEFT JOIN ' . _DB_PREFIX_ . 'sellerinfo s ON po.id_owner=s.id_seller                   
      LEFT JOIN ' . _DB_PREFIX_ . 'sellerinfo_lang sl ON (sl.id_sellerinfo=s.id_sellerinfo AND sl.id_lang=' . intval($context->language->id) . ')           
      LEFT JOIN ' . _DB_PREFIX_ . 'employee e ON (po.`id_owner` = e.`id_employee`)             
      WHERE cp.id_cart=' . intval($this->id) . '             
   ';
   $sellers = Db::getInstance()->ExecuteS($sql);
    if ($this->_products !== null) {
      foreach ($this->_products as $k => $product) {
         foreach ($sellers as $seller) {
            if ($this->_products[$k]['id_product']==$seller['id_product']) {
               if ((int) $seller['id_seller'] == 0)
                  $product['seller_name'] = Configuration::get('PS_SHOP_NAME');
               else
                  $product['seller_name'] = $seller['seller_name'];
               $product['seller_add1'] = $seller['seller_add1'];
               $product['seller_add2'] = $seller['seller_add2'];
               $product['seller_city'] = $seller['seller_city'];
               continue;
            }
         }
         $this->_products[$k] += $product;
      }
        usort($this->_products,function($a,$b){return strnatcmp($a["seller_name"],$b["seller_name"]);});
        return $this->_products;
    }
}


//-------------------------------------------------
// Edit these templates and add the following snippets to display the sellers details
//-------------------------------------------------

blockcart.tpl

Code: Select all
{if $product.seller_name}
<small>
      <p></p>
      <p><strong>{l s='Sold by' mod='blockcart'}: </strong></br><a href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'html':'UTF-8'}" title="{l s='Seller details' mod='blockcart'}">
         {$product.seller_name|truncate:60:'...'|escape:'html':'UTF-8'}{if $product.seller_city}, {$product.seller_city|escape:'html':'UTF-8'}{/if}
      </a></p>
</small>
{/if}


//--------------

shopping-cart-product-line.tpl

Code: Select all
{if $product.seller_name}
<small class="cart_ref">
<strong>{l s='Sold by'}{$smarty.capture.default}</strong></br>
   {$product.seller_name|escape:'html':'UTF-8'}{if $product.seller_city}, {$product.seller_city|escape:'html':'UTF-8'}{/if}
</small>
{/if}


//--------------

* this step only if you have agileshipping installed.

agileshipping -> hookextracarrier.tpl

Code: Select all
{if $product.seller_name}
<p>
<small class="cart_ref">
<strong>{l s='Sold by' mod='agilesellershipping'}: </strong>
   {$product.seller_name|escape:'html':'UTF-8'}{if $product.seller_city}, {$product.seller_city|escape:'html':'UTF-8'}{/if}
</small>
</p>
{/if}


//------------------------

* Cache will need refreshing to see the changes.
carlo.macis_15320
 
Posts: 40
Joined: Wed Feb 24, 2016 3:59 pm

Return to Tips and Tricks for PrestaShop and Agile Modules

Who is online

Users browsing this forum: No registered users and 0 guests