How can we get the product id of each item in shopping cart from the session variable? in zen cart - zen-cart

How can we access the session variable for the shopping cart so that we can get the product id of each product?

$products = $_SESSION['cart']->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
// the product's id is $products[$i]['id']
...
}

Related

Updating the sqflite database if an item to the cart has already been added and creating if it is a new one in flutter

dbHelper.insert(
Cart(
id:null,
productId:snapshot.data[index].name,
productImage:snapshot.data[index].image)
.then(...)
I have created a DBHelper and have succesfully added them to my cart list but now I want to create data for my cart if it's a new item and if the item already exists in my cart list then I want to update the fields in my database.
So how can I query (sqflite) so that I create rows for new items and update for the previous ones through the id(primary) or through(productId which is also unique).
Not tested, but i think you can do custom SQL request like this:
INSERT INTO cart (product_id, ...)
VALUES ('145', ...)
ON CONFLICT(product_id) DO UPDATE SET quantity = quantity + 1;
To execute a custom SQL request with sqflite:
await db.rawQuery('SELECT * from mytable WHERE id = ?', [objectId]);

How to change CreatedBy in work item history?

I am trying to change the CreatedBy field in a work item to a test user I have. The CreatedBy field is being updated on the creation of the work item and I have bypassRules set to true. For a bit I thought the code I wrote was not updating the CreatedBy field because in the History section it still said: "USER created the User Story". Note that "USER" is the member who has the access token.
However, if I pull the work item I just created and pull the CreatedBy information it points out to the test user member, which is correct behavior. So my only problem is that history is not updating, is there a way to change CreatedBy in the history section? Below is a snippet of the code I am using to create the work item.
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.CreatedBy",
Value = workItem.CreatedBy //Represents string "Test User"
}
);
WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "User Story", bypassRules: true).Result;
Console.WriteLine("User Story Successfully Created: User Story #{0}", result.Id);
workItem.ItemId = (int)result.Id;
WorkItem testResult = workItemTrackingHttpClient.GetWorkItemAsync(project, workItem.ItemId).Result;
IdentityRef createdBy = (IdentityRef)testResult.Fields["System.CreatedBy"];
Console.WriteLine(createdBy.DisplayName); //This correctly displays "Test User"
return result;

Product count for anchored category in Magento2

I am using the Megamenu third-party module in Magento 2 and I have customized this module due to some custom requirements.
I need to count product same as display in the admin category section for the anchored category and using the below code
$category->getProductCollection()->count()
this code is returning 0 products while this category is anchored and its subcategory has some product so it should count it subcategories product same as display in the admin section.
Please advise what will the code to get the products.
Thanks,
Please make sure you have successfully reindexed after setting the anchor via php bin/magento indexer/reindex.
Then try following code:
Include product collection factory to your construct
public function __construct(
// ...
\Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection,
// ...
) {
// ...
$this->productCollection = $productCollection;
// ...
}
And count the product collection filtered by your category.
$products = $this->productCollection->create();
$products->addCategoryFilter($category);
$products->count();

How to write query to display all product?

I want to update all products price. For that I want to fetch all records and then later on update the product in Magento.
$product = Mage::getModel('catalog/product');
$product_collection = Mage::getModel('catalog/product')->getCollection();
foreach($product_collection as $product) {
$new_price = $product->getPrice(); // Update price here.
$product->setPrice($new_price)
->save();
}
This will help you to update the price of all products..

Query regarding trigger?

I am having following requirement:
1) To get list of all the users for whome profile has been changed.
2) Then query on FRUP (It is a custom object) to retrieve all the records which are associated with the user whose profile is changed.(FRUP object will contain the list of all the records created by all the users on all the objects say Account, Opportunity)
3) Update FRUP.
For achieving this I wrote one trigger through which i am able to fetch list of all the users whose profile has changed which is as follows:
Trigger UserProfileTrigger on User (before update) {
List<User> usr = new List<User>();
Map<String,String> userMap = new Map<String,String>();
for(User u: Trigger.new){
//Create an old and new map so that we can compare values
User oldOpp = Trigger.oldMap.get(u.ID);
User newOpp = Trigger.newMap.get(u.ID);
//Retrieve the old and new profile
string oldProfileId = oldOpp.profileId;
string newProfileId = newOpp.profileId;
//If the fields are different, the profile has changed
if(oldProfileId != newProfileId){
System.debug('Old:'+oldProfileId);
System.debug('New :'+newProfileId);
usr.add(u);
System.debug('User :'+usr);
}
}
}
Also Following are the fields on custom object FRUP:
1)Owner
2)Name
3)Record ID
4)Folder ID
5)Created By
6)Last Modified By
any help/suggestions??
I'm not sure what field on the FRUP references the user Id it relates to, but you can loop through the FRUP object with something like this:
List<FRUP> frupToUpdate = new List<FRUP>();
for (FRUP f : [
Select
OwnerId,
Name, //etc.
UserId //the field that references the user Id
from FRUP
where userId = : usr]) {
//update field on FRUP, e.g. f.Name = 'New Name';
frupToUpdate.add(f);
}
This selects the FRUP records that relate to the users with changed profiles. It then updates a field on the record and adds the record to a list for updating. Note that this should be after your loop for(User u: Trigger.new). Then update the FRUP records that have changed:
update frupToUpdate;