Display nb of orders on my-account prestashop - smarty

I need to display the data total of orders on the client PrestaShop front-office for PrestaShop 1.7
So the information will be like (you have placed {$orders_count} )
{$orders_count} placed
$this->context->smarty->assign(array(
'totalorders' => $totalorders,
));
$this->setTemplate('customer/my-account');
Regards

Related

setPostedProducts with flat catalog category / product

I'm using setPostedProducts to maintain a sale/discount category.
On my dev machine, it's working (flat catalog category and product is off).
On my stage machine (flat catalog category and product is on), it's not working anymore.
How can I fix this?
category = Mage::getModel('catalog/category')->load($categoryId); // category id of my sales category
$category->setPostedProducts(array(123 => 1)); // product 123 should be the only one in my sales category for testing purposes
$category->save();
Don't really know why, but what solved my problem was adding
Mage::app('admin');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
before executing setPostedProduct().
I suppose that in admin the _getResource() function translates into Mage_Catalog_Model_Resource_Category instead of Mage_Catalog_Model_Resource_Category_Flat

Using Magento API to add all products to root category

I want to set all the products to the root category (next to the current category they are in).
I know the best way to do this is using the Magento API, but can somebody get me started on this?
Just to be clear, i don't want to change the category id, i just want to add another category id to the product.
EDIT
It takes a lot time to check all 3000+ products to see in what other category it is. Example: Root_catId = 175 Product_1 cat = 3 (needs to be: 3, 175) Product_2 cat = 9 (needs to be: 9, 175)
You can do this without using the API but if you want to use the API try following.
You can use following first you need to create a user with permissions to access soap requests in Magento admin
<?php
$proxy = new SoapClient('http://yourmagento/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$result = $proxy->catalogCategoryAssignProduct($sessionId, '3', '10'); // 3 is category id and 10 is product id
You can loop through every product to assign the product to a specific category.
Replace the root category id with the category id which you require.

Magento Bundle Product - Multiple Options with Same products. How to stop Magento from hiding the repetitive products?

I am trying to setup a bundle product within Magento. This product should allow the customer to select 4 free products to include with the bundle. These products can be all different or 4 of the same product.
For example
Free Product 1
Free Product 2
Free Product 3
A customer could select four of Free Product 1, or one of Free Product 1 & 2, with two of Free Product 3.
I am using 4 drop-down input types which each have all three Free products as options. So a customer can choose any of the three products for each Free Gift line item.
Magento is only displaying one of the drop-down select lists, I believe due to the fact that each drop-down contains the same product list.
Where would I need to look to stop Magento from checking if the product options are already listed in a previous selection?
Unless you're doing this programmatically (that is writing the code), there's no way to do this.
When Magento adds a product, it first looks into the quote / shopping cart to see if one already exists. If one does, it pulls that one and adds to the quantity. There is no way to turn this off.
Programmatically, you very manually add an item to a shopping cart. This is how...
$cart = Mage::getSingleton("checkout/cart");
foreach ($products_to_add as $product_id => $custom_options) {
$product = Mage::getModel("catalog/product")->load($product_id);
$options = new Varien_Object(array("options" => $custom_options,
"qty" => 1));
// some products may result in multiple products getting added to cart
// I beleive this pulls them all and sets the custom options accordingly
$add_all = $product->getTypeInstance(true)
->prepareForCartAdvanced($options, $product, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL);
foreach ($add_all as $add_me) {
$item = Mage::getModel('sales/quote_item');
$item->setStoreId(Mage::app()->getStore()->getId());
$item->setOptions($add_me->getCustomOptions())
->setProduct($add_me);
$item->setQty(1);
$cart->getQuote()->addItem($item);
}
}
// when done adding all the items, finally call save on the cart
$cart->save();

How to import Group price in magento through csv?

I need to import wholesale price and retail price both for each products in my website
so I tried to create test product with group price and export that.
and with those fields tried to import, I tried that using both "import" and "dataflow/import", in all case I am getting import successful message , but actually not imported that group prices
By default Magento Import doesn't support for this.
You can either use the custom code as:
// add a pricing to store 1
$product = Mage::getModel('catalog/product')->setStoreId(1)->load(1234);
$product->setData('group_price',array (
array (
"website_id" => 1,
"cust_group" => 2,
"price" => 105
)));
$product->save();

Magento: Import product prices for an additional website?

I have a Magento installation, with two websites on it:
Retail (default)
Trade
Currently all the prices have been imported as default and so the prices are set the same on both websites. I now need to import the lower prices just for the trade website.
I know this can be done manually per product, but how do I go about importing these prices (with their SKU's so that they only apply to the trade store?
Any help much appreciated!
I suggest doing a Product Export first so you can see all of the columns that are used. Locate a SKU from your Trade store and see what the values are for that column.
You should see a column called _product_websites. In my installation, this column has "base" in it. On yours it will probably say "base" and "trade" (whatever you specified for your website code). You can sort by this column in Excel or other spreadsheet software and remove all of the rows that just have "base" in it so you're left with "trade". Now you can update your prices, save the sheet and re-import your file.
hth
You can simply follow the following Magento blog post:
http://www.blog.magepsycho.com/updating-product-prices-in-magento-in-easier-faster-way/
Just you need to add store_id filter in following method as:
function _updatePrices($data){
    $connection     = _getConnection('core_write');
    $sku            = $data[0];
    $newPrice       = $data[1];
$storeId = $data[2];
    $productId      = _getIdFromSku($sku);
    $attributeId    = _getAttributeId();
 
    $sql = "UPDATE " . _getTableName('catalog_product_entity_decimal') . " cped
                SET  cped.value = ?
            WHERE  cped.attribute_id = ?
            AND cped.entity_id = ?
AND store_id = ?";
    $connection->query($sql, array($newPrice, $attributeId, $productId, $storeId));
}
Of course you need to use third column of prices.csv for store_id.
Let me know if that helps.

Resources