Jump to content

wishlist mod


SentiJB
 Share

Recommended Posts

So i don't know how you write a module. 
But this is the coding for a wishlist mod i want to share. 

I use latest version of cubecart 

First Backup all files ! 

It works with me , maybe coding needs some cleanup. 

  • First alter database , DONT FORGET TO ADD THE PREFIX IF YOU USE ONE 
     
CREATE TABLE `CubeCart_WISHLIST` (
  `id` int(10) UNSIGNED NOT NULL,
  `product_id` int(10) UNSIGNED NOT NULL,
  `customer_id` int(10) UNSIGNED NOT NULL,
  `time` int(10) UNSIGNED NOT NULL,
  `WISHLIST_remark` text COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(254) COLLATE utf8_unicode_ci NOT NULL,
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `filepath` varchar(255) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

ALTER TABLE `CubeCart_WISHLIST`
  ADD PRIMARY KEY (`id`);
  
--
-- AUTO_INCREMENT voor geëxporteerde tabellen
--

--
-- AUTO_INCREMENT voor een tabel `_cubecartCubeCart_WISHLIST`
--
ALTER TABLE `CubeCart_WISHLIST`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;

 

in CubeCart_inventory you need to add 

allow_wishlist tinyint(1)   UNSIGNED

also

FIRST STEP Open classes/cubecart.class.php

FIND

$product['description_short'] = $GLOBALS['catalogue']->descriptionShort($product);

BELOW ADD : 

$product['allow_wishlist'] = $product['allow_wishlist'];

FIND :

case 'template':
                    if (isset($_GET['type']) && isset($_GET['module'])) {
                        $module = preg_replace('#[^a-z0-9\_\-]#iU', '', $_GET['module']);
                        $type = preg_replace('#[^a-z0-9\_\-]#iU', '', $_GET['type']);
                        $template = 'modules/'.$type.'/'.$module.'/skin/inline.php';
                        if (file_exists($template)) {
                            $GLOBALS['smarty']->assign('PAGE_CONTENT', file_get_contents($template, false));
                        }
                    }
                break;

BELOW ADD : 

case 'WISHLISTITEMS':
                    $GLOBALS['smarty']->assign('SECTION_NAME', 'wishlistitem');
                    $this->_wishlistitems();
                break;

FIND : 
 

 /**
     * 404 Handling
     */
    private function _404()
    {
        foreach ($GLOBALS['hooks']->load('class.cubecart.404') as $hook) include $hook;
        header("HTTP/1.0 404 Not Found");
        $template = 'templates/content.404.php';
        
        if ($content = $GLOBALS['smarty']->templateExists($template)) {
            $content = $GLOBALS['smarty']->fetch($template);
        } else {
            $content = '<h2>'.$GLOBALS['language']->documents['404_title']."</h2>\r\n<p>".$GLOBALS['language']->documents['404_content'].'</p>';
        }
        $GLOBALS['smarty']->assign('PAGE_CONTENT', $content);
    }

BELOW ADD :

 

/**
     * wishlistmod 
     */

 
private function _WISHLISTITEMS()
    {
        foreach ($GLOBALS['hooks']->load('class.cubecart.construct.wishlist') as $hook) {
            include $hook;
        }
        

        if ($GLOBALS['user']->is()) {

if (isset($_POST['wishlistitem_delete']) && is_array($_POST['wishlistitem_delete'])) {
        foreach ($_POST['wishlistitem_delete'] as $id) {
            $GLOBALS['db']->delete('CubeCart_WISHLIST', array('id' => (int)$id));
        $GLOBALS['gui']->setNotify('Item is verwijderd');
httpredir(currentPage());
        
        }}
            $page = (isset($_GET['p'])) ? $_GET['p'] : 1;
            $per_page = 15;
            $where = array('customer_id' => $GLOBALS['user']->get('customer_id')); 




 if (($wishlistitems = $GLOBALS['db']->select('CubeCart_WISHLIST', false, $where, array('id' => 'DESC'), $per_page, $page, false)) !== false) {
                $GLOBALS['smarty']->assign('PAGINATION', $GLOBALS['db']->pagination($GLOBALS['db']->getFoundRows(), $per_page, $page, 5, $var_name = 'p'));
                 


                    foreach ($wishlistitems as $wishlistitem) {

		    $wishlistitem['datum'] =  formatTime($wishlistitem['time'])  ;
                    $wishlistitem['product_id'] = $wishlistitem['product_id'];
                    $wishlistitem['title'] = $wishlistitem['title'];
                       
 		    $wishlistitem['WISHLIST_remark'] = $wishlistitem['WISHLIST_remark'];
                    $wishlistitem['product_url'] = $GLOBALS['seo']->buildURL('prod', $wishlistitem['product_id']);
                    $vars['wishlistitems'][] = $wishlistitem;
                   
		    }
        


                        
                     
            } else {
                $vars['wishlistitems'] = false;
            }
            $GLOBALS['smarty']->assign('wishlistitemS', $vars['wishlistitems']);
            $GLOBALS['gui']->addBreadcrumb($GLOBALS['language']->account['your_account'], 'index.php?_a=account');
            $GLOBALS['gui']->addBreadcrumb($GLOBALS['language']->wishlist['your_userwishlist'], currentPage());
            $content = $GLOBALS['smarty']->fetch('templates/content.wishlist_user.php');
            $GLOBALS['smarty']->assign('PAGE_CONTENT', $content);
        } else {
            httpredir('?_a=login');
        }

  }

FIND

 /**
     * Products
     */
    private function _product()
    {
        if (($product = $GLOBALS['catalogue']->getProductData($_GET['product_id'])) === false) {
            return;
        }

BELOW ADD : 

 if (isset($_POST['WISHLIST']) && is_array($_POST['WISHLIST'])) {
            $error = false;

            foreach ($GLOBALS['hooks']->load('class.cubecart.wishlist') as $hook) {
                include $hook;
            }
            
            $record = array_map('htmlspecialchars', $_POST['WISHLIST']);
            if ($GLOBALS['user']->is()) {
               
		$record['customer_id'] = $GLOBALS['user']->get('customer_id');
                $record['email']  = $GLOBALS['user']->get('email');            

		
    

            } else {
                $record['customer_id'] = 0;
              

                if (!$GLOBALS['session']->isEmpty('error', 'recaptcha')) {
                    $GLOBALS['gui']->setError($GLOBALS['session']->get('error', 'recaptcha'));
                    $error = true;
                }
            }
            
	                    
 	    $record['product_id']  = (int)$_GET['product_id'];
            $record['time']    = time();
	    $record['title']   = (isset($_POST['title'])) ? $_POST['title'] : '';
            $record['filepath']   = (isset($_POST['filepath'])) ? $_POST['filepath'] : '';

                    
      
     if (($WISHLIST_id = $GLOBALS['db']->insert('CubeCart_WISHLIST', $record)) !== false) {
                  foreach ($GLOBALS['hooks']->load('class.cubecart.wishlist.insert') as $hook) {
                        include $hook;
                    }
                    
                    $GLOBALS['gui']->setNotify($GLOBALS['language']->catalogue['notify_wenslijst_submit']);
                    
                } else {
                    $GLOBALS['gui']->setError($GLOBALS['language']->catalogue['error_review_submit']);
                }
                httpredir(currentPage(null));
            } else {
                foreach ($_POST['WISHLIST'] as $key => $value) {
                    $_POST['WISHLIST'][$key] = htmlspecialchars($value);
                }
                $GLOBALS['smarty']->assign('WRITE', $_POST['WISHLIST']);
            }

SECOND STEP Open skins/YOURSKIN/templates/content.product.php

FIND : 

<div id="quantity_discounts">
	<h4>{$LANG.catalogue.quantity_discounts}</h4>
	<p>{$LANG.catalogue.quantity_discounts_explained}</p>
	<table class="list discounts_table">
		<thead>
		  	<tr>
				<th>{$LANG.common.quantity}</th>
				<th>{$LANG.catalogue.price_per_unit}</th>
		  	</tr>
		</thead>
		<tbody>
		  	{foreach from=$PRODUCT.discounts item=discount}
		  	<tr>
				<td align="center">{$discount.quantity}+</td>
				<td align="center">{$discount.price}</td>
		  	</tr>
		  	{/foreach}
		</tbody>
	</table>
</div>
{/if}

BELOW ADD

{if ($PRODUCT.allow_wishlist) == '1' }

<div id="WISHLIST">
	
	<div id="WISHLIST_read">
		
		<p><a href="#" onclick="$('#WISHLIST_read').slideToggle(); $('#WISHLIST_write').slideToggle(); return false;">Add To Your Wishlist</a></p>
	</div>
	
	<div id="WISHLIST_write" style="display: none;">
		
		<form action="{$VAL_SELF}#WISHLIST_write" method="post">
			{if $IS_USER}
			<p> You're about to add : {$PRODUCT.name} in wishlist. </p>
			<p>
				<label for="rev_title">Product name:</label>
				<input id="rev_title" type="hidden" name="title" value="{$PRODUCT.name}" class="textbox" /> {$PRODUCT.name}
			</p>
 			<p>
				<label for="rev_WISHLIST">Your Remark:</label>
				<textarea id="rev_WISHLIST_remark" name="WISHLIST[WISHLIST_remark]" rows="10" cols="40">{$WRITE.WISHLIST_remark}</textarea>
			</p>
			
			<p>
				<input type="submit" value="Confirm" class="button_submit" />
				<input type="button" onclick="$('#WISHLIST_read').slideToggle(); $('#WISHLIST_write').slideToggle();" value="{$LANG.common.cancel}" class="button_submit" />
			</p>
			
			{else}
			<p>You need to  <a href="login"> login </a> first to add this product : {$PRODUCT.name} to your wishlist </p>
			{/if}
			
			{include file='templates/content.recaptcha.php'}
			
	  	</form>
	</div>
</div>
{/if} 


Open your language file : 

FIND : 

</group>

BELOW ADD : 

 <group name="wishlist">
      <string name="your_userwishlist" introduced="5.0.0"><![CDATA[Items in your wishlist]]></string>
      <string name="notify_wishlist_submit" introduced="5.0.0"><![CDATA[Added to your wishlist]]></string>
           <string name="notify_submit" introduced="5.0.0"><![CDATA[Added]]></string>
 
    </group>

FIND :

<string name="notify_review_submit" introduced="5.0.0">

AFTER :

</string>


ADD BELOW

<string name="notify_wenslijst_submit" introduced="5.0.0"><![CDATA[Added to your wishlist]]></string>

STEP 3  Open skins/YOURSKIN/templates/content.account.php

FIND   

<li><a href="{$STORE_URL}/index.php?_a=profile" title="{$LANG.account.your_details}">{$LANG.account.your_details}</a></li>

ADD : 

<li><a href="{$STORE_URL}/index.php?_a=WISHLISTITEMS" title="Your Wishlist">Your Wishlist</a>{$LANG.account.your_details}</a></li>

STEP 4 : create a new file with the code below , name it  content.wishlist_user.php opload it in templates

 

{if $IS_USER}

<h1><p><img alt="" src="/images/source/WishList-logo.gif" style="width: 284px; height: 150px;" /></p></h1>


<div class="paginate">{if isset($PAGINATION)}{$PAGINATION}</div>
<div class="list">
<form action="{$VAL_SELF}" method="post" enctype="multipart/form-data">
	

<table width="100%">
          
            
              
               <td nowrap="nowrap"><b>Product</b></td>
               <td><b>Added on :</b></td>
               <td><b>Your remark</b></td>
               <td>&nbsp;</td>
               
         
         
           {foreach from=$wishlistitemS item=wishlistitem} <tr>
 
<td align="center"><a href="{$wishlistitem.product_url}" title="View Item"> {$wishlistitem.title} </a></td>
<td> {$wishlistitem.datum} </td>
<td> {$wishlistitem.WISHLIST_remark} </td>          

<td><input type="hidden" name="wishlistitem_delete[]" value="{$wishlistitem.id}" /></span>	<p>
			<input type="submit" value="VERWIJDER" />
		</p>

			</td>
			  
  

         
{/foreach}
{/if}
</table >
</form>

{$PAGINATION}
</div>

{if !isset($PAGINATION)}
<p>No items in your wishlist</p> 
{/if} {/if}


	

NOW WE GONNA DO THE ADMIN AREA :

open admin folder / sources/products.index.inc.php

FIND :

 'digital'   => $GLOBALS['db']->column_sort('digital', $lang['common']['type'], 'sort', $current_page, $_GET['sort']),

ADD AFTER :

'allow_wishlist'   => $GLOBALS['db']->column_sort('allow_wishlist', $lang['common']['allow_wishlist'], 'sort', $current_page, $_GET['sort']),

 

open admin folder / skins/default/templates/products.index.inc.php

FIND

 

<div><label for="condition">{$LANG.catalogue.condition}</label>
            <span>
            <select name="condition" id="condition" class="textbox" type="text">
            <option value="new" {if $PRODUCT.condition == 'new'}selected="selected"{/if}>{$LANG.catalogue.condition_new}</option>
            <option value="used" {if $PRODUCT.condition == 'used'}selected="selected"{/if}>{$LANG.catalogue.condition_used}</option>
            <option value="refurbished" {if $PRODUCT.condition == 'refurbished'}selected="selected"{/if}>{$LANG.catalogue.condition_refurbished}</option>
            </select>
            </span>
         </div>

ADD AFTER : 

<div><label for="allow_wishlist">Can a user add this product to their wishlist</label>
            <span>
            <select name="allow_wishlist" id="allow_wishlist" class="textbox" type="text">
            <option value="1" {if $PRODUCT.allow_wishlist == '1'}selected="selected"{/if}>YES</option>
            <option value="0" {if $PRODUCT.allow_wishlist == '0'}selected="selected"{/if}>No</option>
            </select>
            </span>
         </div


     


      

Edited by SentiJB
Link to comment
Share on other sites

3 hours ago, havenswift-hosting said:

We are developing a full wishlist and giftlist plugin at the moment which will have a huge and wide ranging set of functionality and will be a true plugin

this one i made is free and just very basic...
since you all work with encoded data i needed to write it myself. 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...