Which Association to add to get customfield added to tax - shopware

I am trying to get a customfield in an order inside of the price->calculatedTaxes object which I added to the tax entity.
I dont know what association I have to use to add the customfield to the object. The object is looking like this:
[price:protected] => Shopware\Core\Checkout\Cart\Price\Struct\CartPrice Object
(
[netPrice:protected] => 125.47
[totalPrice:protected] => 128.9
[calculatedTaxes:protected] => Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollection Object
(
[elements:protected] => Array
(
[0] => Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTax Object
(
[tax:protected] => 0
[taxRate:protected] => 0
[price:protected] => 107.41666666667
[extensions:protected] => Array
(
)
)
[19] => Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTax Object
(
[tax:protected] => 3.43
[taxRate:protected] => 19
[price:protected] => 21.483333333333
[extensions:protected] => Array
(
)
)
)
This is my criteria for the orderdata:
$criteria->addFilter(new EqualsFilter('id', $orderId))
->addAssociation('deliveries')
->addAssociation('addresses')
->addAssociation('addresses.country')
->addAssociation('deliveries.shippingOrderAddress.country')
->addAssociation('orderCustomer.salutation')
->addAssociation('transactions.paymentMethod')
->addAssociation('lineItems')
->addAssociation('currency');
Is this even possible or am I completely wrong and this needs to be done completely different to add the customfield to that element?
Thanks
Danny

The CalculatedTax objects your are referring to are not at all direct descendants of the TaxEntity you added your custom fields to. These objects are constructed during runtime through a series of calls where only at the very beginning of the stack an instance of TaxEntity would be present.
There are quite a few levels in the stack between these two instances in fact. Without going into too much details, maybe have a look at the SalesChannelContextFactory where a TaxRuleCollection is stored in the current sales channel context. It has to happen this early on in the stack, since depending on the current user/customer different taxes may be applied, be it net/gross or different tax rates all together.
After all it depends on what you want to do with the data stored in the custom fields. If you need the data for altering the calculation of taxes you might want to store them early on with the creation of the sales channel context as an extension.

Related

Orchard CMS HQL Query Taxonomies : OR in WHERE condition

I am trying to filter the pages that a user sees by checking for common terms between the user and the page. Both the user and the page have a Taxonomy Field of the same type ("Category"), with terms "Standard" and "Premium".
If the category of the user matches with the category of the page, I want to display it, otherwise don't. This works fine with the following IHqlQuery on PagePart:
context.Query.Where(a => a.ContentPartRecord<TermsPartRecord>()
.Property("Terms", "terms"),
x => x.InG("TermRecord.Id", ids));
where ids is the list of term ids of the user.
Apart from the above criteria, I also want to display pages that have no terms attached. This works fine on its own by:
context.Query.Where(a => a.ContentPartRecord<TermsPartRecord>(),
x => x.IsEmpty("Terms")
The problem is when I try to combine the above two conditions. I have tried:
context.Query.Where(a => a.ContentPartRecord<TermsPartRecord>()
.Property("Terms", "terms"),
p => p.Or(x => x.InG("TermRecord.Id", ids), y => y.IsEmpty("Terms")));
The second condition in the Or statement doesn't work because the query is already inside the Terms collection.
I have also tried:
context.Query.Where(a => a.ContentPartRecord<TermsPartRecord>()
p => p.Or(x => x.InG("Terms.TermRecord.Id", ids), y => y.IsEmpty("Terms")));
Here, the first condition is wrong, as I can't access an element of the Terms list with "Terms.TermRecord". This is as far as my Hql capabilities go. Do you have any suggestions? Thank you in advance.
I'm afraid I'm not all that familiar Orchard's query APIs, I always found them tough to use for more complex queries. You could always use raw HQL.
select distinct civ.Id
from Orchard.ContentManagement.Records.ContentItemVersionRecord civ
join civ.ContentItemRecord ci
join ci.ContentType ct
left outer join ci.TermsPartRecord tpr
left outer join tpr.Terms terms
where ct.Name = 'Page' AND (terms.TermRecord.Id in (:ids) OR size(tpr.Terms) = 0)

drupal 6 forms type = select multiple = true... what is the returned value?

There doesn't seem to be any details about this in the forms api. So please forgive my question, but I need to know what is being returned when i submit values from a form field where I can select multiple values. I suspect it is an array, if so, how is it structured? Thanks.
Here is a dump of the value field from the $form_state variable after submission for a form that contains 2 multiple select lists. *Countries and Currencies. As you can see, you are correct, an array of values corresponding to the selected option values is returned for each of the 2 lists:
[values] => Array
(
[name] => PayPal
[ppid] => 17
[countries] => Array
(
[236] => 236
[237] => 237
)
[currencies] => Array
(
[USD] => USD
[EUR] => EUR
[CAD] => CAD
)
[submit] => Submit Details
[form_build_id] => form-d675700e434f656b0e1c7ac4aa91a210
[form_token] => 3405b88547c068a0f6a2742670b2149a
[form_id] => add_payment_method_form
[op] => Submit Details
)

Using object vs Identifier in doctrine 2 DQL

So my friend and me were discussing on whether to use object or id in DQL
I searched on internet but I couldn't find anything in doctrine documentation to see which is the best practice
So the problem is like this
Imagine you have the Category object
You want to get the products that have the price less than 10 so for better performance you make a DQL in the product repository and pass the $category object
My friend says we should pass $category->getId() and search by Id like this
public function findCheapProducts($categoryId){
return $this->createQueryBuilder('p')
->where('p.category = :categoryId')
->andWhere('p.price < :price')
->setParameters(array(
'categoryId' => $categoryId,
'price' => 10
));
}
But what I say is like this
public function findCheapProducts(Category $category){
return $this->createQueryBuilder('p')
->where('p.category = :categoryId')
->andWhere('p.price < :price')
->setParameters(array(
'categoryId' => $category,
'price' => 10
));
}
I wrote the code here so the error or things doesn't really matter to me here
The objective is to see which is the better way to put a condition by the identifier
I'm mixing both depending on the user input. When I already have the object I pass it, if I only have the ID like after a form submission I pass the ID as it would be nonsense to load the model just to pass it to into the querybuilder. (ofc. you need a proper form validation in this case to avoid wrong IDs)

How to efficiently store this document structure in Cassandra?

I want to migrate this complex document structure to cassandra:
foo = {
1: {
:some => :data,
},
2: {
:some => :data
},
...
99 :{
:some => :data
}
'seen' => {1 => 1347682901, 2 => 1347682801}
}
The problem:
It has to be retrievable (readble) as one row/record in ~<5 milliseconds.
So far, I am serializing the data but that is not the optimum as I'm always in need to update the whole thing.
Another thing is, that I would like to use cassandras ttl feature for the values in the 'seen' hash.
Any ideas on how the sub-structures (1..n) could work in cassandra, as they are totally dynamic but should be readable all with one query?
Create a columnFamily. And store as following
rowKey = foo
columnName Value
-----------------------------------
1 {:some => :data,..}
2 {:some => :data,..}
...
...
99 {:some => :data,..}
seen {1 => 1347682901, 2 => 1347682801}
1,2,... "seen" are all dynamic.
If you are worried about updating just one of these columns. It is same as how you insert a new column in a columnfamily. See here Cassandra update column
$column_family->insert('foo', array('42' => '{:some => :newdata,..}'));
I haven't had to use TTL yet. But it's as simple as it is. See pretty easy way to achieve this here Expiring Columns in Cassandra 0.7+
Update
Q1. Just for my understanding: Do you suggest creating 99 columns? Or is it possible to keep that dynamic?
Column family, unlike RDBMS, has flexible structure. You can have unlimited numbers of columns for a row key, dynamically created. For example:
myCcolumnFamily{
"rowKey1": {
"attr1": "some_values",
"attr2": "other_value",
"seen" : 823648223
},
"rowKey2": {
"attr1": "some_values",
"attr3": "other_value1",
"attr5": "other_value2",
"attr7": "other_value3",
"attr9": "other_value4",
"seen" : 823648223
},
"rowKey3": {
"name" : "naishe",
"log" : "s3://bucket42.aws.com/naishe/logs",
"status" : "UNKNOWN",
"place" : "Varanasi"
}
}
This is an old article, worth reading: WTF is a SuperColumn? Here is a typical quote that will answer your query (emphasis mine):
One thing I want to point out is that there’s no schema enforced at this [ColumnFamily] level. The Rows do not have a predefined list of Columns that they contain. In our example above you see that the row with the key “ieure” has Columns with names “age” and “gender” whereas the row identified by the key “phatduckk” doesn’t. It’s 100% flexible: one Row may have 1,989 Columns whereas the other has 2. One Row may have a Column called “foo” whereas none of the rest do. This is the schemaless aspect of Cassandra.
. . . .
Q2. And you suggest serializing the sub-structure?
It's up to you. If you do not want to serialize, you probably should use SuperColumn. My rule of thumb is this. If the value in a column represents a unit whose parts cannot be accessed independently, use Column. (that means serialize value). If column is having fragmented subparts that possibly will require accessing directly use SuperColumn.

Kohana 3 ORM: How to perform query with 2 many to many relationships

I have a products model with 2 many to many relationships defined.
protected $_has_many = array
(
'foodcats' => array('model' => 'foodcat', 'through' => 'products_foodcats'),
'foodgroups' => array('model' => 'foodgroup', 'through' => 'products_foodgroups')
)
I need a query where I find products with a given foodcat id and a given foodgroup name.
I know I can do the following to get all products with a given foodcat id
$foodcat = ORM::factory('foodcat',$foodCatId);
$products = $foodcat->products->find_all();
But how do I query for products in that foodcat that also are in the foodgroup 'Entrees'?
Thanks!
Simply; you don't. What you need is INNER JOIN, like;
ORM::factory('product')
->join('foodcats','INNER')
->on('foodcats.id','=',$foodcats_id)
->join('foodgroups','INNER')
->on('foodgroups.name','=',$foodgroups_name)
->find_all();
in Kohana 3.1 without using DB::expr, will give unknown column error.
ORM::factory('product')
->join('foodcats','INNER')
->on('foodcats.id','=', DB::expr($foodcats_id))
->join('foodgroups','INNER')
->on('foodgroups.name','=', DB::expr($foodgroups_name))
->find_all();

Resources