Y
Y
yanis_kondakov2016-10-25 22:31:21
PHP
yanis_kondakov, 2016-10-25 22:31:21

How to correctly specify the paths to the files?

Trying to use Smarty. I can not solve the problem with the paths to the files.
All code is working.
What is there:
**Smarty**
*CartController.php*

/**
    * 
    * Add product to cart
    * 
    * @param integer id GET - ID of adding product
    * @return json   info about operation (success, number of elements in cart)
    */
    function addtocartAction(){
        $itemId = isset($_GET['id']) ? intval($_GET['id']) : NULL;
        if (! $itemId) {
            return FALSE;
        }
    
        $resData = array();
    
        if (isset($_SESSION['cart'])){
            $_SESSION['cart'][] = $itemId;
            $resData['cntItems'] = count($_SESSION['cart']);
            $resData['success'] = 1;
        } else {
            $resData['success'] = 0;
        }
    
        echo json_encode($resData);
    }

    /**
    * 
    * Making cart page
    * 
    * @link /cart/
    */
    function indexAction($smarty) {
        $itemsIds = isset($_SESSION['cart']) ? $_SESSION['cart'] : array();
    
        $rsCategories = getAllMainCatsWithChildren();
        $rsKits8 = getKitsByCat(4);
        $rsKits16 = getKitsByCat(5);
        $rsSortsHoney = getLastSortsHoney();
        $rsSortsHoneyKits8 = getAllKits8WithSorts();
        $rsSortsHoneyKits16 = getAllKits16WithSorts();
        $rsCartKits = getKitsFromArray($itemsIds);
        $rsCount = getCountKitsFromArray($itemsIds);
   
        $smarty->assign('pageTitle', 'Cart');
        $smarty->assign('rsCategories', $rsCategories);
        $smarty->assign('rsKits8', $rsKits8);
        $smarty->assign('rsKits16', $rsKits16);
        $smarty->assign('rsSortsHoney', $rsSortsHoney);
        $smarty->assign('rsSortsHoneyKits8', $rsSortsHoneyKits8);
        $smarty->assign('rsSortsHoneyKits16', $rsSortsHoneyKits16);
        $smarty->assign('rsCartKits', $rsCartKits);
        $smarty->assign('rsCount', $rsCount);
    
    

        loadTemplate($smarty, 'cart');
    
    }

Then there is this
**JavaScript** function
function addToCart(itemId) {
        $.ajax({
          type: 'POST',
          url: "/cart/addtocart/" + itemId + '/',
          dataType: 'json',
          success: function (data) {
            if (data['success']) {
              $('#cartCntItems').html(data['cntItems']);
              $('#from-ajax').load('http://fashionhoney.local/cart/');
            }
          }
        });
      };

      $(document).on('click', '.addToCart', function (e) {
          e.preventDefault();
          addToCart(this.id.split('_')[1]);
      });

How to change the path in this place?
$('#from-ajax').load('http://fashionhoney.local/cart/');

How can I make this path be created automatically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yanis_kondakov, 2016-10-26
@yanis_kondakov

I solved the problem, you can read here.
www.smarty.net/forums/viewtopic.php?p=91382#91382
If anyone has a better solution, please email me. Thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question