Jump to content

aveeva

Members
  • Posts

    89
  • Joined

  • Last visited

Posts posted by aveeva

  1. @Barand Yes,  actually i am getting error, i don't want keep you disturb, that's what post to other forum,

     

    code: 

     

    			$output .= '
    			<div class="col-sm-3 col-lg-4 col-md-3">
    				<div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;">
    					<audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;">
    						<source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive">
    					</audio>
    					<p align="center"><strong> '. $row['voice_name'] .'</strong></p>
    
    					<p style="font-size: 12px;">
    					Voice Sku		  : '. $row['voice_sku'].' <br />	
    					voice Name        :	'. $row['voice_name'].' <br />
    					Gender		      : '. $row['voice_gender'].' <br />
    					Genres 			  : '. $row['voice_genres'].' <br />
    					Voice Modulation  : '. $row['voice_voice_modulation'].' <br />
    					Languages		  : '. $row['voice_languages'].' <br />
    					Jingle Moods	  : '. $row['voice_jingle_moods'].' <br />
    					Ivr 			  : '. $row['voice_ivr'].' <br /> </p>
    	
    					<button type="button" class="btn btn-primary" style="padding: 5px 83px 5px 83px;" data-voice-sku="'.$row["voice_sku"].'" data-voice-name="'.$row["voice_name"].'">Add to Playlist</button>
    
    				</div>
    
    			</div>
    			';
    		} 
    	}
    	else 
    	{
    		$output = '<h3>No Data Found</h3>';
    	}
    	echo $output;
    }
    ?>
    <script type="text/javascript">
    
    $().ready( function() {
    
    $(".btn").click( function() {
    	var voice_sku = $(this).data("voice_sku");
    	var voice_name = $(this).data("voice_name");
    	
    	$.post(
    		"my_cart.php",
    		{ "voice_sku" : voice_sku, "voice_name" : voice_name},
    		function(resp) {
    			var list = "<tr><td><b>ID</b></td><td><b>Title</b></td></tr>\n";
    			$.each(resp, function(k, v) {
    				list = list + "<tr><td>" + k + "</td><td>" + v + "</td></tr>\n"
    			})
    			$("#playlist").html(list)
    		},
    		"JSON"
    	);
    });
    });
    
    </script>

     

    my_cart.php:

    <?php
    session_start();
    
    if ($_SERVER['REQUEST_METHOD']=='POST') {
        $voice_sku = $_POST['voice_sku'] ?? 0;
        $voice_name = $_POST['voice_name'] ?? '';
        
        if ($voice_sku && $voice_name) {
            $_SESSION['playlist'][$voice_sku] = $voice_name;
            exit(json_encode($_SESSION['playlist'])) ;
        }
    }
    exit("ERROR")  ; 
    ?>

     

    screenshot :

    CPFXWJ.jpg

     

     

     

  2. I am under developing PHP add to cart without DB, so that i am using SESSION, actually get data from fetch_data.php data to my_cart.php using the POST method, successfully retun the values,

    After receiving the post data how can i convert to display like a table.

    workout:

    fetch_data.php return values.

    https://snag.gy/IASCMZ.jpg

    & values received

    https://snag.gy/ojWxHe.jpg

    Here is my my_cart.php :

    // FYI -> Here i am using only two fields :  voice_sku & voice_name 
    
    <table width="100%" cellpadding="6" cellspacing="0">
     <thead>
     <tr>
     <th>Voice Sku</th>
     <th>Voice Name</th>
     <th>Remove</th>
     </tr>
     </thead>
    
     <tbody>
    
     <?php
     session_start();
     $voice_sku = '';
     $voice_name = '';
    
     if(isset($_POST['voice_sku'])&& isset($_POST['voice_name']))
                {
     // print_r($_POST);
     // die();
     
     $voice_sku = $_POST['voice_sku'];
     $voice_name = $_POST['voice_name'];
     $_SESSION['voice_sku'] = $voice_sku;
     $_SESSION['voice_name'] = $voice_name;
     
     
                }   
     var_dump($_SESSION);    
     ?>
    
     <tr>
     <td colspan="5">
     <span style="float:right;text-align: right;">
     <!--  -->
     </span>
     </td>
     </tr>
     <tr>
     <td colspan="5">
     <a href="index.php" class="button">Add More Items</a>
     <button type="submit">Update</button>
     </td>
     </tr>
    
     </tbody>
    </table>

     

  3. String: NodeJs is one of the best technology

    Quote

    NodeJs        is      one       of      the      best      technology
        6               2          3        2         3           4            10


    From above, how to print technology which largest even number.

    How to print the largest even number?

  4. I am working PHP project on localhost using wamp, for debug process we using error_log() function, every time error_log() stored details of the error in wamp/logs, how can I view my error in the same project folder like wamp/www/goodgoal/

    eg: wamp/www/goodgoal/logs/error_log.log

    Note : Pls recommend PHP Quick Debug Tricks

  5. @Barand Here is my inspect element,

     

    DHQTZ6.jpg

     

    and my my_cart.php

     

    <?PHP
    
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    
    // Get details from fetch_data.php
    
    $voice_id = '';
    $voice_name = '';
    
    if(isset($_POST['voice_id']) && isset($_POST['voice_name']))
    {
        $voice_id   = $_POST['voice_id'];
        $voice_name = $_POST['voice_name'];
    }
        echo "$voice_id & $voice_name";
    
    ?>

     

    How to make display  like:

    bWsU6z.jpg

  6. @Barand   Here is my my_cart.php,

    <?PHP
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    // Get details from fetch_data.php
    $voice_id = '';
    $voice_name = '';
    if(isset($_POST['voice_id']) && isset($_POST['voice_name']))
    {
        $voice_id   = $_POST['voice_id'];
        $voice_name = $_POST['voice_name'];
    }
    
        echo "$voice_id & $voice_name";
    
    ?>

     

    My output :

    tObmMZ.jpg

     

     

    if i click add to playlist button the values not reflect on my_cart.php. I just want if i click add to playlist button the each value display on my my_cart.php page like,

    1    1_tamil_voice.mp3

    2    3_tamil_voice.mp3

    3    3_tamil_voice.mp3

     

    Like add-to-cart function. 

  7. 8 minutes ago, Barand said:

    On closer examination, your button script is expecting HTML elements with ids of "voice_id" and "voice_name" with values.

    1. You don't have any such elements
    2. ids must be unique and you will have several buttons and voice_ids.

    i would add hidden fields to hold the names and ids

    
    <input type="hidden" name="voice_id" value="{$row[voice_id]}"   class="voice_id" data-id="{$row[voice_id]}">
                        <input type="hidden" name="voice_name" value="{$row[voice_name]}"   class="voice_name" data-id="{$row[voice_id]}">
                        <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="{$row[voice_id]}">Add to PlayList </button>

    Note the hidden fields and button all share the same data-id values.

    The use those data-id values to get the voces associated with buttons

    
    $('.btn').on('click',function() {
            var vid = $(this).data("id")
            var voice_id     = $(".voice_id[data-id="+vid+"]").val();
            var voice_name  = $(".voice_name[data-id="+vid+"]").val();
    
            $.ajax({
                type      : "POST",
                url       : "my_cart.php",
                datatype : "text",
                data     : {voice_id: voice_id, voice_name: voice_name },
                success: function(data)
                {
                    console.log(data);
                    // console.log('success',data);
                    
                }
            });
        });

     

     

     

    I really appreciate with code help,

     

    Actually, i did mistake in my code

     

    Now i correct,

    <script>
    
    	$('.btn').on('click',function() {
    		var voice_id 	= $("#voice_id");
    		var voice_name  = $("#voice_name");
    
    		$.ajax({
    			type 	 : "POST",
    			url  	 : "my_cart.php",
    			datatype : "text",
    			// data	 : {voice_id: voice_id, voice_name: voice_name },
    			data: "voice_id="+voice_id+"&voice_name="+voice_name,
    
    
    			success: function(data)
    			{
    				console.log(data);
    				// console.log('success',data);
    				
    			}
    		});
    	});
    
    </script>

     

    finally ,my output 

     

    rYQOgn.jpg

    sorry to confusing...

  8. 13 minutes ago, Barand said:

    And your problem is ... ?

    Not shared with my_cart.php file, 

    my my_cart.php file is,

    <?PHP
    // Get details from fetch_data.php
     
    if(isset($_POST['voice_id']) && isset($_POST['voice_name']))
    {
    $voice_id = $_POST['voice_id'];
    $voice_name = $_POST['voice_name'];
    }
     
    echo "$voice_id & $voice_name";
     
    ?>
  9. Here is my PHP, i want to share voice_id and voice_name to another php file using ajax,

     

     

    <?php
    
    
    
    //fetch_data.php
    
    include('database_connection.php');
    
    if(isset($_POST["action"]))
    {
    	$query = "
    		SELECT * FROM voice_bank_data WHERE voice_status = '1'
    	";
    
    	// if(isset($_POST["minimum_price"], $_POST["maximum_price"]) && !empty($_POST["minimum_price"]) && !empty($_POST["maximum_price"]))
    	// {
    	// 	$query .= "
    	// 	 AND product_price BETWEEN '".$_POST["minimum_price"]."' AND '".$_POST["maximum_price"]."'
    	// 	";
    	// }
    
    	// Gender
    	if(isset($_POST["gender"]))
    	{
    		$gender_filter = implode("','", $_POST["gender"]);
    		$query .= "
    		 AND voice_gender IN('".$gender_filter."')
    		";
    	}
    
    	// Genres
    	if(isset($_POST["genres"]))
    	{
    		$genres_filter = implode("','", $_POST["genres"]);
    		$query .= "
    		 AND voice_genres IN('".$genres_filter."')
    		";
    	}
    
    	// Voice Modulation
    	if(isset($_POST["voice_modulation"]))
    	{
    		$voice_modulation_filter = implode("','", $_POST["voice_modulation"]);
    		$query .= "
    		 AND voice_voice_modulation IN('".$voice_modulation_filter."')
    		";
    	}
    
    
    	// Languages
    	if(isset($_POST["languages"]))
    	{
    		$languages_filter = implode("','", $_POST["languages"]);
    		$query .= "
    		 AND voice_languages IN('".$languages_filter."')
    		";
    	}
    
    	// Jingle Moods
    	if(isset($_POST["jingle_moods"]))
    	{
    		$jingle_moods_filter = implode("','", $_POST["jingle_moods"]);
    		$query .= "
    		 AND voice_jingle_moods IN('".$jingle_moods_filter."')
    		";
    	}
    
    	// IVR
    	if(isset($_POST["ivr"]))
    	{
    		$ivr_filter = implode("','", $_POST["ivr"]);
    		$query .= "
    		 AND voice_ivr IN('".$ivr_filter."')
    		";
    	}
    
    	$statement = $connect->prepare($query);
    	$statement->execute();
    	$result = $statement->fetchAll();
    	$total_row = $statement->rowCount();
    	$output = '';
    	if($total_row > 0)
    	{
    		foreach($result as $row)
    		{
    			$output .= '
    			<div class="col-sm-3 col-lg-4 col-md-3">
    				<div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;">
    					<audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;">
    						<source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive">
    					</audio>
    					<p align="center"><strong> '. $row['voice_name'] .'</strong></p>
    
    					<p style="font-size: 12px;">
    					Id		      : '. $row['voice_id'].' <br />
    					Name		      : '. $row['voice_name'].' <br />
    					Gender		      : '. $row['voice_gender'].' <br />
    					Genres 			  : '. $row['voice_genres'].' <br />
    					Voice Modulation  : '. $row['voice_voice_modulation'].' <br />
    					Languages		  : '. $row['voice_languages'].' <br />
    					Jingle Moods	  : '. $row['voice_jingle_moods'].' <br />
    					Ivr 			  : '. $row['voice_ivr'].' <br /> </p>
    					<button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;">Add to PlayList </button>
    
    
    				</div>
    
    			</div>
    			';
    		} 
    	}
    	else 
    	{
    		$output = '<h3>No Data Found</h3>';
    	}
    	echo $output;
    }
    ?>
    
    <script>
    
    	$('.button').on('click',function() {
    		var voice_id 	= $("#voice_id").val();
    		var voice_name  = $("#voice_name").val();
    
    		$.ajax({
    			type 	 : "POST",
    			url  	 : "my_cart.php",
    			datatype : "text",
    			data	 : {voice_id: voice_id, voice_name: voice_name },
    			success: function(data)
    			{
    				console.log(data);
    				// console.log('success',data);
    				
    			}
    		});
    	});
    
    </script>

    Not shared the details,

  10. After correcting the syntax error, my logic not working but observer triggered.

     

    <?php
    ini_set('display_errors', '1');
    
    Mage::log('fine dude', null, 'logfile.log');
    class Brst_Test_Model_Observer
    {
        //Put any event as per your requirement
        public function logCartAdd() {
            Mage::log('good dude', null, 'logfile.log');
    
            // try{
    
            $product = Mage::getModel('catalog/product')
                            ->load(Mage::app()->getRequest()->getParam('product', 0));
            $cart_qty = (int) Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
    
            if ($product->getId()==31588 && $cart_qty > 0) {
                Mage::throwException("You can not add This special Product, empty cart before add it");
            }
    
            // $quote = Mage::getSingleton('checkout/session')->getQuote();
            // if ($quote->hasProductId(2)) 
            //{
            //  Mage::getSingleton("core/session")->addError("Cart has Special Product you can not add another");
            //  return;
            // }
            $quote = Mage::getModel('checkout/cart')->getQuote();
            foreach ($quote->getAllItems() as $item) {
                $productId = $item->getProductId();
                if($productId==31588){
                    Mage::throwException("Cart has Special Product you can not add another");
                }
            }
    
        // }catch(Exception $e)
        // {
        //     // Mage::log($e, null, 'logfile.log');
        //     echo $e->getMessage();
        // }
    
        }
    }
    ?>

    finally not working but observer triggered,  still other products added to cart if restricted products available in cart. How to do my module a better way?

    FYI: logfile.log

     

    2019-06-28T06:05:00+00:00 DEBUG (7): fine dude
    2019-06-28T06:05:00+00:00 DEBUG (7): good dude

     

  11. I just try with try cache error handling :

     

    <?php
    ini_set('display_errors', '1');
    
    Mage::log('fine dude', null, 'logfile.log');
    class Brst_Test_Model_Observer
    {
        //Put any event as per your requirement
        public function logCartAdd() {
            Mage::log('good dude', null, 'logfile.log');
            try{
            $product = Mage::getModel('catalog/product')
                            ->load(Mage::app()->getRequest()->getParam('product', 0));
            $cart_qty = (int) Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
    
            if ($product->getId()==31588 && $cart_qty > 0) {
                Mage::throwException("You can not add This special Product, empty cart before add it");
            }
    
            // $quote = Mage::getSingleton('checkout/session')->getQuote();
            // if ($quote->hasProductId(2)) 
            //{
            //  Mage::getSingleton("core/session")->addError("Cart has Special Product you can not add another");
            //  return;
            // }
            $quote = Mage::getModel('checkout/cart')->getQuote();
            foreach ($quote->getAllItems() as $item) {
                $productId = $item->getProductId();
                if($productId==31588){
                    Mage::throwException("Cart has Special Product you can not add another");
                }
            }
        }catch(Exception $e)
        {
            // Mage::log($e, null, 'logfile.log');
            echo $e->getMessage();
        }
    
        }
    }
    ?>

    and my logfile.log file

     

    2019-06-28T05:50:11+00:00 DEBUG (7) : fine dude
    2019-06-28T05:50:11+00:00 DEBUG (7) : good dude

    If i am right?

  12. @NotionCommotion If i try with try and cache debug, no error, 

     

     

    <?php
    ini_set('display_errors', '1');
    
     Mage::log('Hy observer called', null, 'add_to_cart_logfile.log');
    class Brst_Test_Model_Observer
    {
        //Put any event as per your requirement
        public function logCartAdd() {
            try{
            Mage::log('test', null, 'add_to_cart_logfile.log');
            $product = Mage::getModel('catalog/product')
                            ->load(Mage::app()->getRequest()->getParam('product', 0));
            $cart_qty = (int) Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
    
            if ($product->getId()==31588 && cart_qty > 0) {
                Mage::throwException("You can not add This special Product, empty cart before add it");
            }
    
            // $quote = Mage::getSingleton('checkout/session')->getQuote();
            // if ($quote->hasProductId(2)) 
            //{
            //  Mage::getSingleton("core/session")->addError("Cart has Special Product you can not add another");
            //  return;
            // }
            $quote = Mage::getModel('checkout/cart')->getQuote();
            foreach ($quote->getAllItems() as $item) {
                $productId = $item->getProductId();
                if($productId==31588){
                    Mage::throwException("Cart has Special Product you can not add another");
                }
            }
            }catch(Exception $e)
            {
                Mage::log($e, null, 'add_to_cart_logfile.log');
            }
    
        }
    }
    ?>

     

  13. Created module like No other products add to cart if restricted product available in cart and vice versa.

    My Module :

    • app/etc/modules/Brst_Test.xml
    <?xml version="1.0"?>
    <config>
        <modules>
            <Brst_Test>
                <active>true</active>
                <codePool>community</codePool>
            </Brst_Test>
        </modules>
    </config>

    This is my observer file

    • app/code/community/Brst/Test/Model/Observer.php
    <?php
    ini_set('display_errors', '1');
    
    // Mage::log('Hy observer called', null, 'logfile.log');
    class Brst_Test_Model_Observer
    {
        //Put any event as per your requirement
        public function logCartAdd() {
            $product = Mage::getModel('catalog/product')
                            ->load(Mage::app()->getRequest()->getParam('product', 0));
            $cart_qty = (int) Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
    
            if ($product->getId()==31588 && cart_qty > 0) {
                Mage::throwException("You can not add This special Product, empty cart before add it");
            }
    
            // $quote = Mage::getSingleton('checkout/session')->getQuote();
            // if ($quote->hasProductId(2)) 
            //{
            //  Mage::getSingleton("core/session")->addError("Cart has Special Product you can not add another");
            //  return;
            // }
            $quote = Mage::getModel('checkout/cart')->getQuote();
            foreach ($quote->getAllItems() as $item) {
                $productId = $item->getProductId();
                if($productId==31588){
                    Mage::throwException("Cart has Special Product you can not add another");
                }
            }
    
        }
    }
    ?>

     

    • app/code/community/Brst/Test/etc/config.xml
    <?xml version="1.0"?>
    <config>
        <modules>
            <Brst_Test>
               <version>0.1.0</version>
            </Brst_Test>
        </modules>
        <global>
            <models>
                <brst_test>
                    <class>Brst_Test_Model</class>
                </brst_test>
            </models>
        </global>
        <frontend>
            <events>
                <controller_action_predispatch_checkout_cart_add>
                    <observers>
                        <brst_test_log_cart_add>
                            <class>brst_test/observer</class>
                            <method>logCartAdd</method>
                        </brst_test_log_cart_add>
                    </observers>
                </controller_action_predispatch_checkout_cart_add>
            </events>
        </frontend>
    </config>

     

    Not working, how to solve the error?

     
  14.  

    My index.php,

    
     
    $output .= '
    		<div class="col-sm-3 col-lg-4 col-md-3">
    			<div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;">
    				<audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;">
    					<source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive">
    				</audio>
    				<p align="center"><strong> '. $row['voice_name'] .'</strong></p>
    
    				<p style="font-size: 12px;">
    				Id				  : '. $row['voice_id'].' <br />
    				Name			  : '. $row['voice_name'].' <br />
    				Gender		      : '. $row['voice_gender'].' <br />
    				Genres 			  : '. $row['voice_genres'].' <br />
    				Voice Modulation  : '. $row['voice_voice_modulation'].' <br />
    				Languages		  : '. $row['voice_languages'].' <br />
    				Jingle Moods	  : '. $row['voice_jingle_moods'].' <br />
    				Ivr 			  : '. $row['voice_ivr'].' <br /> </p>
    				
    				<button type="button" class="btn btn-primary" type="submit" onclick="addCart('. "'".$row["voice_id"]."'".','."'". $row["voice_name"]."'".');" style="padding: 5px 83px 5px 83px;">Add to PlayList </button>

    same page ajax :

     

    <script>
    function addCart(voice_id, voice_name)
    	{
    
    		$.ajax({
    			type: 'POST',
    			url: 'cart.php',
    			data: {
    				voice_id   : voice_id,
    				voice_name : voice_name
    			},
    			dataType: 'text',
    			success: function(data) {
    				// alert(data);
    
    
    			}
    		});
    	}
    $(document).ready(function(){
    
    });
    </script>

    and get.php

     

    <?php 
    
    
    $voice_id =" ";
    $voice_name=" ";
    if(isset($_POST['voice_id']) && isset($_POST['voice_name']))
    {
        $voice_id = $_POST['voice_id'];
        $voice_name = $_POST['voice_name'];
    
    }
    
    echo "$voice_id, . "&". , $voice_name";
    
    
    ?>

    if click button, the value send but the get.php not properly get the value and display on the php page.

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.