Magento + ebay
Count matching values of a array in PHP
Very simple function to count matching values of a array.
function array_match_count($aa)
{
$bb=array_unique($aa);
print_r($bb);
$numb=array();
foreach($aa as $a)
{
foreach($bb as $b)
{
if(!isset($numb[$b]))
{
$numb[$b]=0;
}
if($b==$a)
{
$numb[$b]++;
}
}
}
echo '<hr>';
print_r($numb);
} //func end
$aa=array(
1=>'uk',
2=>'usa',
3=>'uk',
4=>'uk',
5=>'roi',
6=>'roi',
7=>'uae',
8=>'bd',
9=>'bd',
10=>'bd',
11=>'bd' );
array_match_count($aa);
Output:
Array ( [1] => uk [2] => usa [5] => roi [7] => uae [8] => bd )
Array ( [uk] => 3 [usa] => 1 [roi] => 2 [uae] => 1 [bd] => 4 )
Magento CMS Page menu
We can put this function in helper of any extension and call from theme. or you we can put this directly from theme. ![]()
or create a file template/page/html/leftmeu.phtml
and add block
<block type="page/html_header" name="leftmenu" as="leftmenu" template="page/html/leftmenu.phtml"/>
in page.xml (above or below breadcrumbs)
then you can call from theme
<?php echo $this->getChildHtml('leftmenu') ?>
public function getcmsdata()
{
$cncollection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());
$cncollection->getSelect()->where('is_active = 1');
foreach ($cncollection as $page)
{
$PageData = $page->getData();
if($PageData['menu']!= 'false')
{
$lnk[] =array('value'=>Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).$PageData['identifier'], 'label'=>$PageData['title']);
}
}
return $lnk;
}
Product level shipping in Magento
Magento don’t let you set shipping cost in product level. You can do it by flatrate shipping method
Create a attribute shipping_world and add to your default attribute set.
overwrite/extend the flatrate carrier model of magento.
The value given in shipping_world attribute of product will be the flat shipping rate of that product.
class Mage_Shipping_Model_Carrier_Flatrate
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
protected $_code = 'flatrate';
protected $_isFixed = true;
/**
* Enter description here...
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty() * $child->getQty();
}
}
} elseif ($item->getFreeShipping()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') { // per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') { // per item
$shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
} else {
$shippingPrice = false;
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
$shippingPrice = $this->get_pro_ship();
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('flatrate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('flatrate');
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
public function getAllowedMethods()
{
return array('flatrate'=>$this->getConfigData('name'));
}
public function get_pro_ship()
{
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('checkout/session');
$cart_items = $session->getQuote()->getAllItems();
$_helper = Mage::helper('catalog/output');
$custom_ship=0;
foreach( $cart_items as $items ){
$cur_fproduct = Mage::getModel('catalog/product')->load($items->getProduct_id());
$custom_ship +=($items->getQty())*($_helper->productAttribute($cur_fproduct, $cur_fproduct->getShippingWorld(), 'shipping_world'));
}
return $custom_ship ;
}// function end
}
Easy Multiple Copy to Clipboard by ZeroClipboard
It almost stuck my head today when fixing this multiple zeroclipboard button by ZeroClipboard library.
<script type="text/javascript" src="ZeroClipboard.js"></script>
<script language="JavaScript">
////copy to clip
var clip = null;
function $(id) { return document.getElementById(id); }
function init()
{
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );
}
function move_swf(ee)
{
copything = document.getElementById(ee.id+"_text").value;
clip.setText(copything);
if (clip.div)
{
clip.receiveEvent('mouseout', null);
clip.reposition(ee.id);
}
else{ clip.glue(ee.id); }
clip.receiveEvent('mouseover', null);
}
</script>
<body onload="init();">
<table width="0" border="0">
<tr>
<td><input type='text' id='textid_text' value='your text' /></td>
<td><div id='textid' onMouseOver='move_swf(this)' class='clip_button'>COPY</div></td>
</tr>
<tr>
<td><input type='text' id='textid2_text' value='your text 2' /></td>
<td><div id='textid2' onMouseOver='move_swf(this)' class='clip_button'>COPY</div></td>
</tr>
<tr>
<td><input type='text' id='textid3_text' value='your text 3' /></td>
<td><div id='textid3' onMouseOver='move_swf(this)' class='clip_button'>COPY</div></td>
</tr>
<tr>
<td><input type='text' id='textid4_text' value='your text 4' /></td>
<td><div id='textid4' onMouseOver='move_swf(this)' class='clip_button'>COPY</div></td>
</tr>
<tr>
<td><input type='text' id='textid5_text' value='your text 5' /></td>
<td><div id='textid5' onMouseOver='move_swf(this)' class='clip_button'>COPY</div></td>
</tr>
</table>
</body>
You can generate above html dynamically by loop and generate ids with unique values.
See Demo
Download