How to get Current Product Seller Id in magento.If I can get the Id I can show up their address country. Is there Anyone can help me with this?
I get the seller name by attribute
<?php echo $_product->getAttributeText('creator_id');?>
From Product ID you can get its seller name, below is code sample for it ( magento 1.9)
$ProductID = 1000; ///$_product->getProductId(); you can get it like this
$allSellers= Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('mageproductid',array('eq'=> $ProductID ));
$sellerID = 0;
foreach ($allSellers as $seller) {
$sellerID= $seller->getUserid(); // here you have seller ID
$sellerName = Mage::getModel('customer/customer')->load($sellerID)->getName(); // here you have seller name
}
This codes can be used if you are using Marketplace Extension.
Assuming the product ID is 10.
$prodID = 10;
$collection_prod = Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('mageproductid', array('eq'=>$prodID));
$sellerID = '';
foreach($collection_prod as $collection){
$sellerID = $collection->getUserid(); //get the seller ID
}
$sellerAddress_Collection = Mage::getModel('customer/address')->getCollection()->addFieldToFilter('parent_id', array('eq'=>$sellerID));
foreach($sellerAddress_Collection as $sellerAddress_Collections){
$addressID = $sellerAddress_Collections->getEntityId(); //get the address ID of the seller
$seller_collection_address = Mage::getModel('customer/address')->load($addressID); // load the address ID of the seller
$zipcode = $seller_collection_address->getPostcode(); //zipcode
$country_id = $seller_collection_address->getCountryId(); //country id
$city = $seller_collection_address->getCity(); // City
$street1 = $seller_collection_address->getStreet(1); //street 1
$street2 = $seller_collection_address->getStreet(2); //street 2
$tel = $seller_collection_address->getTelephone(); //Telephone
}
Related
What I want to accomplish is to get a unique list of the names of customers with their lastest consultation date.
I have defined these models in my models.py file, using mySQL as my database:
class Customer(models.Model):
class ContactChoice(models.IntegerChoices):
DO_NOT_CONTACT = 0
EMAIL = 1
TXT_SMS_VIBER = 2
mobile_num = models.CharField('Mobile Number', max_length=10, unique=True,)
email_add = models.EmailField('Email', max_length=150, unique=True,)
last_name = models.CharField('Last Name', max_length=30,)
first_name = models.CharField('First Name', max_length=30,)
contact_for = models.CharField('Contact For', max_length=60,)
contact_on = models.IntegerField('Contact Using', choices=ContactChoice.choices, default=0,)
customer_consent = models.BooleanField('With Consent?', default=False,)
def __str__(self):
return self.last_name + ', ' + self.first_name
class Consultation(models.Model):
consultation_date = models.DateTimeField('Date of Consultation', default=now)
customer = models.ForeignKey(Customer, on_delete=models.SET_DEFAULT, default=1)
concern = models.ForeignKey(SkinConcern, on_delete=models.SET_DEFAULT, default=1)
consultation_concern = models.CharField('Other Concerns', max_length=120, null=True,)
product = models.ForeignKey(Product, on_delete=models.SET_DEFAULT, default=1)
user = models.ForeignKey(User, on_delete=models.SET_DEFAULT, default=1)
store = models.ForeignKey(Store, on_delete=models.SET_DEFAULT, default=1)
consultation_is_active = models.BooleanField('Is Active', default=True)
def __str__(self):
return self.customer.last_name + ", " + self.customer.first_name
In my views.py, I have this for the Consultations page:
distinct = Consultation.objects.values('customer').annotate(consultation_count=Count('customer')).filter(consultation_count=1)
consults = Consultation.objects.filter(customer__in=[item['customer'] for item in distinct])
As mentioned, I was expecting to get a unique list of customer names with their latest consultation dates. This code results in only 1 record being shown.
Can you point me in the right direction for this? Thank you in advance! :)
As I see it, what you're doing right now is gathering all the customers that only had one consultation. This won't return what you want.
I believe you can use the latest() method for this: https://docs.djangoproject.com/en/4.1/ref/models/querysets/#latest
This is untested code, but you could do something like this:
# gather all the customers
customers = Customer.objects.all()
# for every customer, get their latest consultation date, using the .latest() function
for customer in customers:
try:
latest_consultation = Consultation.objects.filter(customer=customer).latest('consultation_date')
latest_consultation_date = latest_consultation.consultation_date
except Consultation.DoesNotExist:
latest_consultation_date = None
customer.latest_consultation_date = latest_consultation_date
you can then loop over it as so:
for customer in customers:
if customer.latest_consultation_date:
print(customer.latest_consultation_date)
I am querying a MySQL database and getting the only 2 columns I need alert_limit and customer_email. I am planning to be able to select each email individually with the alert limit value and use them as variables into a SMTP param.
Update: to answer Luuk's question I am using the SimplySql Powershell module. https://www.powershellgallery.com/packages/SimplySql/1.6.2
$query = Invoke-SqlQuery -query "SELECT distinct alerts.* FROM alerts, joblog Where alert_enabled=1 and joblog.customer_id=alerts.customer_id AND alert_limit;" | select "alert_limit", "customer_email"
The result is:
alert_limit customer_email
----------- --------------
150 user1#email1.com
12000 user2#email2.com
10000 user3#email3.com
I am trying to send an individual email to each customer_email with their alert)limit in the body as below:
$Parameters = #{
ToAddress = '$customer_email'
FromAddress = "notifications#system.com"
Subject = "Credits"
Body = "your credits are bellow" '$alert_limit'
but I struggle to select individual entries. thanks
I have done it.
ForEach($customer in $query) {
$alert_limit= $customer.alert_limit
$customer_email = $customer.customer_email
$Parameters = #{
ToAddress ="$customer_email"
FromAddress = "notifications#system.com"
Subject = "Credits"
Body = "your credits are below<br> $alert_limit"
}
}
I am trying to obtain results for a given member where status is pending or accepted doing the below:
$status1 = "Pending";
$status2 = "Attended";
$query = $conn->prepare('SELECT * FROM members WHERE member_id=:mID AND status=:status1 OR status=:status2');
$query->execute(array(':mID' => $mID,':status1' => $status1, ':status2' => $status2));
if ($query->rowCount() > 0) {
//start to create my table
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
//create variable, loop through and fill the table etc
}
}else{
echo "something";
}
This displays data - however, it even obtains results not specific to the member id (mID). Meaning other members data too!
I'm clearly missing something and or my query is wrong but struggling to find anything..
Any help appreciated.
You need to look at operator precedence for your database. You're doing this:
SELECT * FROM members WHERE member_id = :mID AND status = :status1 OR status = :status2;
Which most likely results in this:
SELECT * FROM members WHERE (member_id = :mID AND status = :status1) OR status = :status2;
But that's not what you want, so you will have to explicitly use parens like this:
SELECT * FROM members WHERE member_id = :mID AND (status = :status1 OR status = :status2);
Alternatively, you can use IN so that there's no OR:
SELECT * FROM members WHERE member_id = :mID AND status IN (:status1, :status2);
I have two tables TABLE users and TABLE assign_project. I need to get those user id that are not in assign_project table based on the role_id.
The fields in users table:
- user_id
- username
- role_id
- company_id
The fields in the assign_project table:
- id
- project_id
- user_id
The code is
$company_id = 1;
//get the project details of the project $project_id
$projects = Project::where('project_id','=',$project_id)->get();
//get the company id of the project $project_id
$company_id = Project::where('project_id','=',$project_id)->value('company_id');
//get the users whom the $project_id is assigned
$users = DB::table('assign_project')
->where('project_id','=', $project_id)
->get();
// if $project_id is assigned to any user retrieve only those
//with role id = 2 and with the company id $company_id
//whom $project_id is not assigned
foreach ($users as $row) {
$designation = User::where('user_id','<>',$row->assigned_to)
->where('role_id','=',2)
->where('company_id','=',$company_id)
->get();
}
I am not getting the output.
let say i have a table named banners. the columns are:
+---+-------------------------------+
|ID | link | image | active |
+---+-------+-------------+---------+
|1 |#link1 | image1 | 0 |
|2 |#link2 | image2 | 1 |
|3 |#link3 | image3 | 0 |
+---+-------+-------------+---------+
there you can see row #2 is active. how can i update next row based on latest active row? also if active row is the last row, then set first row as active row.
PS: I will do the query using cron, update every 2 hours for example. no problem about the cron, I did it.
use this stored procedure :
DELIMITER //
CREATE PROCEDURE updateActiveRow()
BEGIN
SELECT MAX(ID) INTO #activeID FROM banners WHERE active;
UPDATE banners SET active=1 WHERE ID > #activeID LIMIT 1;
IF ROW_COUNT() = 0 THEN
UPDATE banners SET active=1 ORDER BY ID LIMIT 1;
END IF;
UPDATE banners SET active=0 WHERE ID = #activeID;/*do this only if you want to deactivate current active row*/
END //
Thanks to all,
I solved it myself. here is the code
class Job{
private $con;
function __construct(){
$this->con = mysqli_connect('localhost', 'root', '', 'egoji');
}
function getCurrentActiveID(){
$q = "SELECT id FROM banners WHERE active='1'";
$result = $this->con->query($q);
$row = mysqli_fetch_assoc($result);
return $row['id'];
}
function getNextID($id){
$q = "SELECT MIN(id) AS id FROM banners WHERE id > '{$id}'";
$result = $this->con->query($q);
$row = mysqli_fetch_assoc($result);
return $row['id'];
}
function isLastRow(){
$currentActiveId = $this->getCurrentActiveID();
$q = "SELECT id FROM banners ORDER BY id DESC LIMIT 1";
$result = $this->con->query($q);
$row = mysqli_fetch_assoc($result);
return $row['id'] == $currentActiveId ? true:false;
}
function updateFirstRow(){
$q = "SELECT MIN(id) AS id FROM banners";
$result = $this->con->query($q);
$row = mysqli_fetch_assoc($result);
$this->deactivateAll();
$update_q = "UPDATE banners SET active='1' WHERE id='{$row['id']}'";
$this->con->query($update_q);
}
function updateNextRow(){
$currentActiveId = $this->getCurrentActiveID();
$nextID = $this->getNextID($currentActiveId);
$this->deactivateAll();
$update_q = "UPDATE banners SET active='1' WHERE id='{$nextID}'";
$this->con->query($update_q);
}
function deactivateAll(){
$update_q = "UPDATE banners SET active='0'";
$this->con->query($update_q);
}
function doit(){
if($this->isLastRow()){
$this->updateFirstRow();
}else{
$this->updateNextRow();
}
}
}
$job = new Job;
$job->doit();
I am open to any suggestions or correction.
Tested SQL Fiddle
SET #activeID = (SELECT ID FROM Banners WHERE active = 1);
SET #isLast = (SELECT COUNT(*) FROM Banners) LIKE #activeID;
UPDATE Banners
SET active = IF(ID = #activeID, 0, IF(ID = #activeID+1, 1, active));
UPDATE Banners
SET active = IF(#isLast AND ID = 1, 1, active);