Shopify, Shopify Apps, Magento, WordPress, Codeigniter, Joomla, Big Commerce | PHP
Thursday, 4 August 2016
Add custom price on frontend using admin side attribute
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Test_Test>
<version>0.1.0</version>
</Test_Test>
</modules>
<global>
<helpers>
<test>
<class>Test_Test_Helper</class>
</test>
</helpers>
<models>
<test>
<class>Test_Test_Model</class>
<resourceModel>test_mysql4</resourceModel>
</test>
</models>
</global>
<frontend>
<events>
<catalog_product_collection_load_after> <!-- identifier of the event we want to catch -->
<observers>
<catalog_product_collection_load_after_handler> <!-- identifier of the event handler -->
<type>model</type> <!-- class method call type; valid are model, object and singleton -->
<class>test/observer</class> <!-- observers class alias -->
<method>catalogProductLoadAfter</method> <!-- observer's method to be called -->
<args></args> <!-- additional arguments passed to observer -->
</catalog_product_collection_load_after_handler>
</observers>
</catalog_product_collection_load_after>
</events>
</frontend>
</config>
Observer.php
<?php
class Test_Test_Model_Observer
{
public function catalogProductLoadAfter(Varien_Event_Observer $observer)
{
$collection = $observer->getEvent()->getCollection();
foreach ($collection as $product)
{
$produ = Mage::getModel('catalog/product')->load($product->getId())->getData('discountatt');
$originalprice = $product->getPrice();
$customprice = $originalprice+$produ;
$product->setPrice($customprice);
// $product->setData('my_price',$customprice);
}
// echo '<pre>';print_r($produ); exit;
// $product = $observer->getEvent()->getProduct();
/*$originalprice = $product->getPrice();
$product->setPrice($customprice);*/
}
}
Wednesday, 27 July 2016
Show count in li css
CSS counters are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they're used. This lets you adjust the appearance of content based on its placement in the document. CSS counters are an implementation of Automatic counters and numbering in CSS 2.1.
The value of a counter is manipulated through the use of counter-reset. counter-increment can be displayed on a page using the counter() or counters() function of the content property.
Using counters
To use a CSS counter, it must first be reset to a value (0 by default). To add the value of a counter to an element, use the counter() function. The following CSS adds to the beginning of each h3 element "Section <the value of the counter>:".
Saturday, 9 July 2016
What is the scope of variables in JavaScript?
JavaScript programmers are practically ranked by how well they understand scope.
1. A globally-scoped variable
1. A globally-scoped variable
var a = 1;
// global scope
function one() {
alert(a); // alerts '1'
}
2. Local scope
var a = 1;
function two(a) {
alert(a); // alerts the given argument, not the global value of '1'
}
// local scope again
function three() {
var a = 3; // alerts '3'
alert(a);
}
3. Intermediate: No such thing as block scope in JavaScript (ES5; ES6 introduces
let
)var a = 1;
function four() {
if (true) {
var a = 4;
}
alert(a); // alerts '4', not the global value of '1'
}
4. Intermediate: Object properties
var a = 1;
function five() {
this.a = 5;
}
alert(new five().a); // alerts '5'
5. Advanced: Closure
var a = 1;
var six = (function() {
var a = 6;
return function() {
// JavaScript "closure" means I have access to 'a' in here,
// because it is defined in the function in which I was defined.
alert(a); // alerts '6'
};
})();
6. Advanced: Prototype-based scope resolution
var a = 1;
function seven() {
this.a = 7;
}
// [object].prototype.property loses to
// [object].property in the lookup chain. For example...
// Won't get reached, because 'a' is set in the constructor above.
seven.prototype.a = -1;
// Will get reached, even though 'b' is NOT set in the constructor.
seven.prototype.b = 8;
alert(new seven().a); // alerts '7'
alert(new seven().b); // alerts '8'
7. Global+Local: An extra complex Case
var x = 5;
(function () {
console.log(x);
var x = 10;
console.log(x);
})();
This will print out undefined and 10 rather than 5 and 10 since JavaScript always moves variable declarations (not initializations) to the top of the scope, making the code equivalent to:
var x = 5;
(function () {
var x;
console.log(x);
x = 10;
console.log(x);
})();
8. Catch clause-scoped variable
var e = 5;
console.log(e);
try {
throw 6;
} catch (e) {
console.log(e);
}
console.log(e);
Friday, 8 July 2016
How to change author name on GitHub/Bitbucket?
If you put your GitHub username and email account in those settings, your commits will accurately reflect your GitHub account as the right author.
$ git config --global user.name "Scott Chacon"
$ git config --global user.email "schacon@gmail.com"
How to Append Javascript/Jquery code run using PHP
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
var option_count = "text something";
$(document).ready(function(){
$('div').append('<?php echo add_option("' + option_count + '"); ?>');
});
</script>
<div></div>
<?php
ini_set('display_errors', 1);
function add_option($count) { ob_start();
echo $count;
$stuff = ob_get_contents();
ob_end_clean();
echo replace_newline($stuff);
}
function replace_newline($string) {
return trim((string)str_replace(array("\r", "\r\n", "\n", "\t"), ' ', $string));
}
?>
Monday, 27 June 2016
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource
Write following code into cross-origin's .htaccess file
Example:
Ex 2 .
in php file : header('Access-Control-Allow-Origin: *');
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
Example:
- You open "http://example.com" (here you see the cross-origin error of http://abc.com)
- Open .htaccess of abc.com and paste above code.
Ex 2 .
in php file : header('Access-Control-Allow-Origin: *');
Subscribe to:
Posts (Atom)